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

Skip to content

Commit 677233f

Browse files
committed
Merged revisions 8543 via svnmerge from
https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v1_0_maint ........ r8543 | weathergod | 2010-07-13 21:42:19 -0500 (Tue, 13 Jul 2010) | 2 lines Added documentation and examples for new, easier Axes3D use. ........ svn path=/trunk/matplotlib/; revision=8544
1 parent 625632c commit 677233f

22 files changed

Lines changed: 97 additions & 32 deletions

doc/mpl_toolkits/mplot3d/tutorial.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ mplot3d tutorial
77

88
Getting started
99
===============
10-
Create a new :class:`matplotlib.figure.Figure` and an
11-
:class:`~mpl_toolkits.mplot3d.Axes3D` object in it::
10+
An Axes3D object is created just like any other axes using
11+
the projection='3d' keyword.
12+
Create a new :class:`matplotlib.figure.Figure` and
13+
add a new axes to it of type :class:`~mpl_toolkits.mplot3d.Axes3D`::
1214

13-
import pylab
14-
fig = pylab.figure()
15+
import matplotlib.pyplot as plt
1516
from mpl_toolkits.mplot3d import Axes3D
16-
ax = Axes3D(fig)
17+
fig = pyplt.figure()
18+
ax = fig.add_subplot(111, projection='3d')
1719

1820
Line plots
1921
====================
@@ -39,13 +41,15 @@ Surface plots
3941

4042
.. plot:: mpl_examples/mplot3d/surface3d_demo.py
4143
.. plot:: mpl_examples/mplot3d/surface3d_demo2.py
44+
.. plot:: mpl_examples/mplot3d/surface3d_demo3.py
4245

4346
Contour plots
4447
=============
4548
.. automethod:: Axes3D.contour
4649

4750
.. plot:: mpl_examples/mplot3d/contour3d_demo.py
4851
.. plot:: mpl_examples/mplot3d/contour3d_demo2.py
52+
.. plot:: mpl_examples/mplot3d/contour3d_demo3.py
4953

5054
Filled contour plots
5155
====================
@@ -75,3 +79,11 @@ Text
7579

7680
.. plot:: mpl_examples/mplot3d/text3d_demo.py
7781

82+
Subplotting
83+
====================
84+
Having multiple 3D plots in a single figure is the same
85+
as it is for 2D plots. And you can mix 2D and 3D plots
86+
into the same figure.
87+
88+
.. plot:: mpl_examples/mplot3d/subplot3d_demo.py
89+
.. plot:: mpl_examples/mplot3d/mixed_subplots_demo.py

examples/mplot3d/2dcollections3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import matplotlib.pyplot as plt
44

55
fig = plt.figure()
6-
ax = Axes3D(fig)
6+
ax = fig.gca(projection='3d')
77

88
x = np.linspace(0, 1, 100)
99
y = np.sin(x * 2 * np.pi) / 2 + 0.5

examples/mplot3d/bars3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44

55
fig = plt.figure()
6-
ax = Axes3D(fig)
6+
ax = fig.add_subplot(111, projection='3d')
77
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
88
xs = np.arange(20)
99
ys = np.random.rand(20)

examples/mplot3d/contour3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import matplotlib.pyplot as plt
33

44
fig = plt.figure()
5-
ax = axes3d.Axes3D(fig)
5+
ax = fig.add_subplot(111, projection='3d')
66
X, Y, Z = axes3d.get_test_data(0.05)
77
cset = ax.contour(X, Y, Z)
88
ax.clabel(cset, fontsize=9, inline=1)

examples/mplot3d/contour3d_demo2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import matplotlib.pyplot as plt
33

44
fig = plt.figure()
5-
ax = axes3d.Axes3D(fig)
5+
ax = fig.gca(projection='3d')
66
X, Y, Z = axes3d.get_test_data(0.05)
77
cset = ax.contour(X, Y, Z, 16, extend3d=True)
88
ax.clabel(cset, fontsize=9, inline=1)

examples/mplot3d/contour3d_demo3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import matplotlib.pyplot as plt
33

44
fig = plt.figure()
5-
ax = axes3d.Axes3D(fig)
5+
ax = fig.gca(projection='3d')
66
X, Y, Z = axes3d.get_test_data(0.05)
77
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
88
cset = ax.contour(X, Y, Z, zdir='z', offset=-100)

examples/mplot3d/contourf3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import matplotlib.pyplot as plt
33

44
fig = plt.figure()
5-
ax = axes3d.Axes3D(fig)
5+
ax = fig.gca(projection='3d')
66
X, Y, Z = axes3d.get_test_data(0.05)
77
cset = ax.contourf(X, Y, Z)
88
ax.clabel(cset, fontsize=9, inline=1)

examples/mplot3d/hist3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44

55
fig = plt.figure()
6-
ax = Axes3D(fig)
6+
ax = fig.add_subplot(111, projection='3d')
77
x, y = np.random.rand(2, 100) * 4
88
hist, xedges, yedges = np.histogram2d(x, y, bins=4)
99

examples/mplot3d/lines3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
mpl.rcParams['legend.fontsize'] = 10
77

88
fig = plt.figure()
9-
ax = Axes3D(fig)
9+
ax = fig.gca(projection='3d')
1010
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
1111
z = np.linspace(-2, 2, 100)
1212
r = z**2 + 1
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Demonstrate the mixing of 2d and 3d subplots
3+
"""
4+
from mpl_toolkits.mplot3d import Axes3D
5+
import matplotlib.pyplot as plt
6+
import numpy as np
7+
8+
def f(t):
9+
s1 = np.cos(2*np.pi*t)
10+
e1 = np.exp(-t)
11+
return np.multiply(s1,e1)
12+
13+
14+
################
15+
# First subplot
16+
################
17+
t1 = np.arange(0.0, 5.0, 0.1)
18+
t2 = np.arange(0.0, 5.0, 0.02)
19+
t3 = np.arange(0.0, 2.0, 0.01)
20+
21+
fig = plt.figure()
22+
fig.suptitle('A tale of 2 subplots')
23+
ax = fig.add_subplot(2, 1, 1)
24+
l = ax.plot(t1, f(t1), 'bo',
25+
t2, f(t2), 'k--', markerfacecolor='green')
26+
ax.grid(True)
27+
ax.set_ylabel('Damped oscillation')
28+
29+
30+
#################
31+
# Second subplot
32+
#################
33+
ax = fig.add_subplot(2, 1, 2, projection='3d')
34+
X = np.arange(-5, 5, 0.25)
35+
xlen = len(X)
36+
Y = np.arange(-5, 5, 0.25)
37+
ylen = len(Y)
38+
X, Y = np.meshgrid(X, Y)
39+
R = np.sqrt(X**2 + Y**2)
40+
Z = np.sin(R)
41+
42+
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
43+
linewidth=0, antialiased=False)
44+
45+
ax.set_zlim3d(-1, 1)
46+
47+
plt.show()
48+

0 commit comments

Comments
 (0)