3D subfigures in matplotlib?

MATLABdude matlab.dude at mbnet.fi
Tue Apr 5 06:17:34 EDT 2011

```How can I make maybe 3D subfigures with Python and matplotlib?

I found the following example (http://matplotlib.sourceforge.net/
examples/mplot3d/subplot3d_demo.html), but it doesn't work.
---
from mpl_toolkits.mplot3d.axes3d import Axes3D
import matplotlib.pyplot as plt

# imports specific to the plots in this example
import numpy as np
from matplotlib import cm
from mpl_toolkits.mplot3d.axes3d import get_test_data

fig = plt.figure(figsize=(9.5,5.0))

#---- First subplot
ax = fig.add_subplot(1, 2, 1, projection='3d')
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
linewidth=0, antialiased=False)
ax.set_zlim3d(-1.01, 1.01)

fig.colorbar(surf, shrink=0.5, aspect=10)

#---- Second subplot
ax = fig.add_subplot(1, 2, 2, projection='3d')
X, Y, Z = get_test_data(0.05)
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

plt.show()
----

The error message is:
----
>>> ax = fig.add_subplot(1, 2, 1, projection='3d')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/matplotlib/figure.py", line 677,
projection_class = get_projection_class(projection)
File "/usr/lib/pymodules/python2.6/matplotlib/projections/
__init__.py", line 61, in get_projection_class
raise ValueError("Unknown projection '%s'" % projection)
ValueError: Unknown projection '3d'
>>>
----

I am using Python 2.6.6., and matplotlib 0.99.3.

How can I make several subfigures in 3D?

```