We'll now plot a 3D plot, where the Sin
function is plotted against the sum of the square values of the two axes:
>>> from mpl_toolkits.mplot3d import Axes3D >>> fig = plt.figure() >>> ax = Axes3D(fig) >>> X = np.arange(-4, 4, 0.25) >>> Y = np.arange(-4, 4, 0.25) >>> X, Y = np.meshgrid(X, Y) >>> R = np.sqrt(X**2 + Y**2) >>> Z = np.sin(R) >>> ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='hot')
After the preceding code is executed we'll get the following output:
In the preceding code, we defined the x and y axes with values ranging from -4 to 4. We created a coordinate matrix with meshgrid()
, then squared the values of x and y, and finally, summed them up. This was then fed to the plot_surface
function. The rstride
and cstride
parameters in simple terms help in sizing the cell on the surface.
Let's adjust the view using view_int
. The following is the view at 0
degree elevation and 0...