Hello all,

I have always been a bit troubled with how Axes3D object is a bit of a
2nd-class citizen in matplotlib.  In particular, it is very common to create
a new axes using .add_subplot() or .gca(), but you can't do that with
Axes3D.  You also can't create subplots of 3d figures, you have to create
multiple figures with single 3d plots in them.

My examination off the code have not revealed anything that prevents this
from happening.  Currently, the gca() and add_subplot() functions accept a
kwarg of 'projection' which allows one to specify the name of a registered
axes object.  Currently axes.Axes, polar and a few others are registered,
with axes.Axes being default.

I have found that 3 lines of code in the axes3d module to have it add the
Axes3D class to the registry.  Using a name of '3d', one can specify the
projection to gain a Axes3d object.  Note, you will still have to import the
Axes3D object as usual.  Attached is a patch for axes3d.py and a file that
could be added to mpl_examples/.  Give it a shot and let me know how it
works for you!

Enjoy!
Ben Root

P.S. - Can you just imagine subplots of animated 3d plots? wink... wink...
Index: matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py
===================================================================
--- matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py	(revision 8481)
+++ matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py	(working copy)
@@ -37,6 +37,7 @@
     """
     3D axes object.
     """
+    name = '3d'
 
     def __init__(self, fig, rect=None, *args, **kwargs):
         '''
@@ -1210,3 +1211,11 @@
     Z = Z * 500
     return X, Y, Z
 
+
+
+########################################################
+# Register Axes3D as a 'projection' object available 
+# for use just like any other axes
+########################################################
+import matplotlib.projections as proj
+proj.projection_registry.register(Axes3D)
from mpl_toolkits.mplot3d.axes3d import Axes3D
from matplotlib import cm
#from matplotlib.ticker import LinearLocator, FixedLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()

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)

#ax.w_zaxis.set_major_locator(LinearLocator(10))
#ax.w_zaxis.set_major_formatter(FormatStrFormatter('%.03f'))

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

from mpl_toolkits.mplot3d.axes3d import get_test_data
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()

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to