Skip to content

Commit 6596c4a

Browse files
committed
support 3d plots in arbitrary axes; thanks Ben Root
svn path=/trunk/matplotlib/; revision=8497
1 parent 9ca5db0 commit 6596c4a

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2010-07-05 Added Ben Root's patch to put 3D plots in arbitrary axes,
2+
allowing you to mix 3d and 2d in different axes/subplots or
3+
to have multiple 3D plots in one figure. See
4+
examples/mplot3d/subplot3d_demo.py - JDH
5+
16
2010-07-05 Preferred kwarg names in set_xlim are now 'left' and
27
'right'; in set_ylim, 'bottom' and 'top'; original
38
kwargs are still accepted without complaint. - EF

examples/api/compound_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
vertices = np.array(vertices, float)
2222
path = Path(vertices, codes)
2323

24-
pathpatch = PathPatch(path, facecolor='red', edgecolor='green')
24+
pathpatch = PathPatch(path, facecolor='None', edgecolor='green')
2525

2626
fig = plt.figure()
2727
ax = fig.add_subplot(111)

examples/mplot3d/subplot3d_demo.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from mpl_toolkits.mplot3d.axes3d import Axes3D
2+
from matplotlib import cm
3+
#from matplotlib.ticker import LinearLocator, FixedLocator, FormatStrFormatter
4+
import matplotlib.pyplot as plt
5+
import numpy as np
6+
7+
fig = plt.figure()
8+
9+
ax = fig.add_subplot(1, 2, 1, projection='3d')
10+
X = np.arange(-5, 5, 0.25)
11+
Y = np.arange(-5, 5, 0.25)
12+
X, Y = np.meshgrid(X, Y)
13+
R = np.sqrt(X**2 + Y**2)
14+
Z = np.sin(R)
15+
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
16+
linewidth=0, antialiased=False)
17+
ax.set_zlim3d(-1.01, 1.01)
18+
19+
#ax.w_zaxis.set_major_locator(LinearLocator(10))
20+
#ax.w_zaxis.set_major_formatter(FormatStrFormatter('%.03f'))
21+
22+
fig.colorbar(surf, shrink=0.5, aspect=5)
23+
24+
from mpl_toolkits.mplot3d.axes3d import get_test_data
25+
ax = fig.add_subplot(1, 2, 2, projection='3d')
26+
X, Y, Z = get_test_data(0.05)
27+
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
28+
29+
plt.show()
30+

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Axes3D(Axes):
3737
"""
3838
3D axes object.
3939
"""
40+
name = '3d'
4041

4142
def __init__(self, fig, rect=None, *args, **kwargs):
4243
'''
@@ -1210,3 +1211,11 @@ def get_test_data(delta=0.05):
12101211
Z = Z * 500
12111212
return X, Y, Z
12121213

1214+
1215+
1216+
########################################################
1217+
# Register Axes3D as a 'projection' object available
1218+
# for use just like any other axes
1219+
########################################################
1220+
import matplotlib.projections as proj
1221+
proj.projection_registry.register(Axes3D)

0 commit comments

Comments
 (0)