Wireframes and Surface Plots
Today we’ll be talking about wireframe and surface plots. We’ll be using our example from the previous lecture and modify it. Here it is again:
%matplotlib inline
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
x = y = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(np.sqrt(X**2 + Y**2))
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
ax.contour(X, Y, Z, 20, zdir='z', cmap=mpl.cm.Blues)
To plot wireframes and surfaces you can use the plot_wireframe and plot_surface respectively. Let’s strt with a wireframe:
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
ax.plot_wireframe(X, Y, Z, cmap=mpl.cm.Blues)
You can also specify the maximum number of samples in each direction. By default these two keyword arguments are set to 50. Let’s change one of them to 10 to see the difference.
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
ax.plot_wireframe(X, Y, Z, rcount=10, cmap=mpl.cm.Blues)
Now the grid is less dense in the vertical direction. Let’s now set ccount to 10 and use the default value of 50 for rcount:
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
ax.plot_wireframe(X, Y, Z, ccount=10, cmap=mpl.cm.Blues)
Now the grid is less dense in the horizontal direction. And now let’s set both these arguments to very small numbers:
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
ax.plot_wireframe(X, Y, Z, rcount=5, ccount=5, cmap=mpl.cm.Blues)
And now let’s have a look at surface plots. They are just like the wireframe plots with the difference that the faces are filled polygons. Let’s modify our example again:
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
ax.plot_surface(X, Y, Z, cmap=mpl.cm.Blues)
Just like with wireframes, you can use the rcount and ccount keyword arguments:
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
ax.plot_surface(X, Y, Z, rcount=20, ccount=10, cmap=mpl.cm.Blues)