|
1 | | -from mpl_toolkits.mplot3d.axes3d import Axes3D |
2 | | -import matplotlib.pyplot as plt |
3 | | - |
| 1 | +''' |
| 2 | +Demonstrate including 3D plots as subplots. |
| 3 | +''' |
4 | 4 |
|
5 | | -# imports specific to the plots in this example |
6 | | -import numpy as np |
| 5 | +import matplotlib.pyplot as plt |
| 6 | +from mpl_toolkits.mplot3d.axes3d import Axes3D, get_test_data |
7 | 7 | from matplotlib import cm |
8 | | -from mpl_toolkits.mplot3d.axes3d import get_test_data |
| 8 | +import numpy as np |
9 | 9 |
|
10 | | -# Twice as wide as it is tall. |
| 10 | + |
| 11 | +# set up a figure twice as wide as it is tall |
11 | 12 | fig = plt.figure(figsize=plt.figaspect(0.5)) |
12 | 13 |
|
13 | | -#---- First subplot |
| 14 | +#=============== |
| 15 | +# First subplot |
| 16 | +#=============== |
| 17 | +# set up the axes for the first plot |
14 | 18 | ax = fig.add_subplot(1, 2, 1, projection='3d') |
| 19 | + |
| 20 | +# plot a 3D surface like in the example mplot3d/surface3d_demo |
15 | 21 | X = np.arange(-5, 5, 0.25) |
16 | 22 | Y = np.arange(-5, 5, 0.25) |
17 | 23 | X, Y = np.meshgrid(X, Y) |
18 | 24 | R = np.sqrt(X**2 + Y**2) |
19 | 25 | Z = np.sin(R) |
20 | 26 | surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, |
21 | 27 | linewidth=0, antialiased=False) |
22 | | -ax.set_zlim3d(-1.01, 1.01) |
23 | | - |
| 28 | +ax.set_zlim(-1.01, 1.01) |
24 | 29 | fig.colorbar(surf, shrink=0.5, aspect=10) |
25 | 30 |
|
26 | | -#---- Second subplot |
| 31 | +#=============== |
| 32 | +# Second subplot |
| 33 | +#=============== |
| 34 | +# set up the axes for the second plot |
27 | 35 | ax = fig.add_subplot(1, 2, 2, projection='3d') |
| 36 | + |
| 37 | +# plot a 3D wireframe like in the example mplot3d/wire3d_demo |
28 | 38 | X, Y, Z = get_test_data(0.05) |
29 | 39 | ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10) |
30 | 40 |
|
|
0 commit comments