Time for action – plotting in three dimensions
We will plot a simple three-dimensional function:
- Use the 3D keyword to specify a three-dimensional projection for the plot:
ax = fig.add_subplot(111, projection='3d')
- To create a square two-dimensional grid, use the
meshgrid()
function to initialize thex
andy
values:u = np.linspace(-1, 1, 100) x, y = np.meshgrid(u, u)
- We will specify the row strides, column strides, and the color map for the surface plot. The strides determine the size of the tiles in the surface. The choice for color map is a matter of taste:
ax.plot_surface(x, y, z, rstride=4, cstride=4, cmap=cm.YlGnBu_r)
The result is the following ...
Get NumPy : Beginner's Guide - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.