Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edd492e

Browse files
committed
added mpl_toolkits.mplot3d
svn path=/trunk/matplotlib/; revision=7041
1 parent 5b09a7a commit edd492e

File tree

12 files changed

+1914
-6
lines changed

12 files changed

+1914
-6
lines changed

CHANGELOG

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
======================================================================
2-
2008-04-12 Release 0.98.5.3 at r7038
2+
3+
2008-04-14 Added Jonathan Taylor's Reinier Heeres' port of John
4+
Porters' mplot3d to svn trunk. Package in
5+
mpl_toolkits.mplot3d and demo is examples/mplot3d/demo.py.
6+
Thanks Reiner
7+
38

49
2009-04-06 The pdf backend now escapes newlines and linefeeds in strings.
510
Fixes sf bug #2708559; thanks to Tiago Pereira for the report.

doc/users/credits.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,9 @@ Michael Droettboom
166166
base. He also rewrote the transformation infrastructure to support
167167
custom projections and scales.
168168

169+
John Porter, Jonathon Taylor and Reinier Heeres
170+
John Porter wrote the mplot3d module for basic 3D plotting in
171+
matplotlib, and Jonathon Taylor and Reinier Heeres ported it to the
172+
refactored transform trunk.
173+
169174

doc/users/toolkits.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,19 @@ Excel. This toolkit ships with matplotlib, but requires
3737

3838
Natgrid
3939
========
40-
40+
4141
mpl_toolkits.natgrid is an interface to natgrid C library for gridding
4242
irregularly spaced data. This requires a separate installation of the
4343
natgrid toolkit from the sourceforge `download
4444
<http://sourceforge.net/project/showfiles.php?group_id=80706&package_id=142792>`_
4545
page.
46-
46+
47+
.. _toolkit_mplot3d:
48+
49+
mplot3d
50+
===========
51+
52+
mpl_toolkits.mplot3d provides some basic 3D plotting (scatter, surf,
53+
line, mesh) tools. Not the fastest or feature complete 3D library out
54+
there, but ships with matplotlib and thus may be a lighter weight
55+
solution for some use cases.

examples/mplot3d/demo.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import random
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
import mpl_toolkits.mplot3d.axes3d as axes3d
5+
from matplotlib.colors import Normalize, colorConverter
6+
7+
def test_scatter():
8+
f = plt.figure()
9+
ax = axes3d.Axes3D(f)
10+
11+
n = 100
12+
for c,zl,zh in [('r',-50,-25),('b',-30,-5)]:
13+
xs,ys,zs = zip(*
14+
[(random.randrange(23,32),
15+
random.randrange(100),
16+
random.randrange(zl,zh)
17+
) for i in range(n)])
18+
ax.scatter3D(xs,ys,zs, c=c)
19+
20+
ax.set_xlabel('------------ X Label --------------------')
21+
ax.set_ylabel('------------ Y Label --------------------')
22+
ax.set_zlabel('------------ Z Label --------------------')
23+
24+
def test_wire():
25+
f = plt.figure()
26+
ax = axes3d.Axes3D(f)
27+
28+
X,Y,Z = axes3d.get_test_data(0.05)
29+
ax.plot_wireframe(X,Y,Z, rstride=10,cstride=10)
30+
ax.set_xlabel('X')
31+
ax.set_ylabel('Y')
32+
ax.set_zlabel('Z')
33+
34+
def test_surface():
35+
f = plt.figure()
36+
ax = axes3d.Axes3D(f)
37+
38+
X,Y,Z = axes3d.get_test_data(0.05)
39+
ax.plot_surface(X,Y,Z, rstride=10,cstride=10)
40+
ax.set_xlabel('X')
41+
ax.set_ylabel('Y')
42+
ax.set_zlabel('Z')
43+
44+
def test_contour():
45+
f = plt.figure()
46+
ax = axes3d.Axes3D(f)
47+
48+
X,Y,Z = axes3d.get_test_data(0.05)
49+
cset = ax.contour3D(X,Y,Z)
50+
ax.clabel(cset, fontsize=9, inline=1)
51+
ax.set_xlabel('X')
52+
ax.set_ylabel('Y')
53+
ax.set_zlabel('Z')
54+
55+
def test_contourf():
56+
f = plt.figure()
57+
ax = axes3d.Axes3D(f)
58+
59+
X,Y,Z = axes3d.get_test_data(0.05)
60+
cset = ax.contourf3D(X,Y,Z)
61+
ax.clabel(cset, fontsize=9, inline=1)
62+
ax.set_xlabel('X')
63+
ax.set_ylabel('Y')
64+
ax.set_zlabel('Z')
65+
66+
def test_plot():
67+
f = plt.figure()
68+
ax = axes3d.Axes3D(f)
69+
70+
xs = np.arange(0,4*np.pi+0.1,0.1)
71+
ys = np.sin(xs)
72+
ax.plot(xs,ys, label='zl')
73+
ax.plot(xs,ys+max(xs),label='zh')
74+
ax.plot(xs,ys,dir='x', label='xl')
75+
ax.plot(xs,ys,dir='x', z=max(xs),label='xh')
76+
ax.plot(xs,ys,dir='y', label='yl')
77+
ax.plot(xs,ys,dir='y', z=max(xs), label='yh')
78+
ax.set_xlabel('X')
79+
ax.set_ylabel('Y')
80+
ax.set_zlabel('Z')
81+
ax.legend()
82+
83+
def test_polys():
84+
f = plt.figure()
85+
ax = axes3d.Axes3D(f)
86+
87+
cc = lambda arg: colorConverter.to_rgba(arg, alpha=0.6)
88+
89+
xs = np.arange(0,10,0.4)
90+
verts = []
91+
zs = [0.0,1.0,2.0,3.0]
92+
for z in zs:
93+
ys = [random.random() for x in xs]
94+
ys[0],ys[-1] = 0,0
95+
verts.append(zip(xs,ys))
96+
97+
from matplotlib.collections import PolyCollection
98+
poly = PolyCollection(verts, facecolors = [cc('r'),cc('g'),cc('b'),
99+
cc('y')])
100+
poly.set_alpha(0.7)
101+
ax.add_collection(poly,zs=zs,dir='y')
102+
103+
ax.set_xlim(0,10)
104+
ax.set_ylim(-1,4)
105+
ax.set_zlim(0,1)
106+
107+
def test_scatter2D():
108+
f = plt.figure()
109+
ax = axes3d.Axes3D(f)
110+
111+
xs = [random.random() for i in range(20)]
112+
ys = [random.random() for x in xs]
113+
ax.scatter(xs, ys)
114+
ax.scatter(xs, ys, dir='y', c='r')
115+
ax.scatter(xs, ys, dir='x', c='g')
116+
117+
def test_bar2D():
118+
f = plt.figure()
119+
ax = axes3d.Axes3D(f)
120+
121+
for c,z in zip(['r','g','b', 'y'],[30,20,10,0]):
122+
xs = np.arange(20)
123+
ys = [random.random() for x in xs]
124+
ax.bar(xs, ys, z=z, dir='y', color=c, alpha=0.8)
125+
126+
if __name__ == "__main__":
127+
128+
test_scatter()
129+
test_wire()
130+
test_surface()
131+
test_contour()
132+
test_contourf()
133+
test_plot()
134+
test_polys()
135+
test_scatter2D()
136+
# test_bar2D()
137+
138+
plt.show()

examples/pylab_examples/finance_work2.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,21 @@ def moving_average_convergence(x, nslow=26, nfast=12):
216216

217217

218218

219+
class MyLocator(mticker.MaxNLocator):
220+
def __init__(self, *args, **kwargs):
221+
mticker.MaxNLocator.__init__(self, *args, **kwargs)
222+
223+
def __call__(self, *args, **kwargs):
224+
return mticker.MaxNLocator.__call__(self, *args, **kwargs)
225+
219226
# at most 5 ticks, pruning the upper and lower so they don't overlap
220227
# with other ticks
221-
ax2.yaxis.set_major_locator(mticker.MaxNLocator(5, prune='both'))
222-
ax3.yaxis.set_major_locator(mticker.MaxNLocator(5, prune='both'))
228+
#ax2.yaxis.set_major_locator(mticker.MaxNLocator(5, prune='both'))
229+
#ax3.yaxis.set_major_locator(mticker.MaxNLocator(5, prune='both'))
230+
231+
ax2.yaxis.set_major_locator(MyLocator(5, prune='both'))
232+
ax3.yaxis.set_major_locator(MyLocator(5, prune='both'))
233+
223234
plt.show()
224235

225236

examples/tests/backend_driver.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@
240240

241241
]
242242

243+
mplot3d_dir = os.path.join('..', 'mplot3d')
244+
mplot3d_files = [
245+
'demo.py',
246+
]
247+
243248
# dict from dir to files we know we don't want to test (eg examples
244249
# not using pyplot, examples requiring user input, animation examples,
245250
# examples that may only work in certain environs (usetex examples?),
@@ -271,7 +276,8 @@ def report_missing(dir, flist):
271276
files = (
272277
[os.path.join(api_dir, fname) for fname in api_files] +
273278
[os.path.join(pylab_dir, fname) for fname in pylab_files] +
274-
[os.path.join(units_dir, fname) for fname in units_files]
279+
[os.path.join(units_dir, fname) for fname in units_files] +
280+
[os.path.join(mplot3d_dir, fname) for fname in mplot3d_files]
275281
)
276282

277283
# tests known to fail on a given backend

lib/mpl_toolkits/mplot3d/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)