Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Josh
- %matplotlib notebook
- from mpl_toolkits.mplot3d import axes3d
- import matplotlib.pyplot as plt
- import numpy as np
- # Prepare the figure container
- fig = plt.figure()
- ax = axes3d.Axes3D(fig)
- # Prepare the 2D domain: x from -1 to 1 and y from -1 to 1
- x,y = np.meshgrid(np.linspace(-3,3,41),np.linspace(-3,3,41))
- z = x*np.exp((-(x**2)/2)-((y**3)/3)+y)
- # Plot the surface
- ax.plot_surface(x,y,z,rstride=1, cstride=1, cmap="jet", vmin=np.nanmin(z), vmax=np.nanmax(z), lw=1, antialiased=True)
- # Set all labels, view, and then plot
- ax.set_xlabel('x')
- ax.set_ylabel('y')
- ax.set_zlabel('f(x,y)')
- ax.set_xticks([-3,-2,-1,0,1,2,3])
- ax.set_yticks([-3,-2,-1,0,1,2,3])
- ax.set_zticks([-3,-2,-1,0,1,2,3])
- ax.view_init(68,-140)
- plt.show()
- %matplotlib notebook
- from mpl_toolkits.mplot3d import axes3d
- import matplotlib.pyplot as plt
- import numpy as np
- # Prepare the figure container
- fig = plt.figure()
- ax = axes3d.Axes3D(fig)
- # Prepare the 2D domain: x from -1 to 1 and y from -1 to 1
- x,y = np.meshgrid(np.linspace(-3,3,41),np.linspace(-3,3,41))
- z = x*np.exp((-(x**2)/2)-((y**3)/3)+y)
- flagoffx = np.logical_and(x >= 0, x <= 1)
- flagoffy = np.logical_and(y >= 0, y <= 1)
- flagoff = np.logical_and(flagoffx,flagoffy)
- z[flagoff] = np.nan
- # Plot the surface
- ax.plot_surface(x,y,z,rstride=1, cstride=1, cmap="jet", vmin=np.nanmin(z), vmax=np.nanmax(z), lw=1, antialiased=True)
- # Set all labels, view, and then plot
- ax.set_xlabel('x')
- ax.set_ylabel('y')
- ax.set_zlabel('f(x,y)')
- ax.set_xticks([-3,-2,-1,0,1,2,3])
- ax.set_yticks([-3,-2,-1,0,1,2,3])
- ax.set_zticks([-3,-2,-1,0,1,2,3])
- ax.view_init(68,-140)
- plt.show()
- %matplotlib notebook
- import matplotlib
- import matplotlib.pyplot as plt
- import numpy as np
- # Prepare the figure container
- fig, ax = plt.subplots()
- # Prepare the 2D domain: x from -1 to 1 and y from -1 to 1
- x,y = np.meshgrid(np.linspace(-3,3,41),np.linspace(-3,3,41))
- z = x*np.exp((-(x**2)/2)-((y**3)/3)+y)
- # Plot the surface
- cnt = ax.contour(z, cmap=matplotlib.cm.RdBu, vmin=abs(z).min(), vmax=abs(z).max(), extent=[-3, 3, -3, 3])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement