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

Skip to content

Commit d79c33c

Browse files
committed
DOC Cleaning up mplot3d/wire3d* examples: comments/docstrings, tweaks, and refactoring. [MEP12]
1 parent 885ce29 commit d79c33c

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed
Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,45 @@
1-
from __future__ import print_function
21
"""
3-
A very simple 'animation' of a 3D plot
2+
A very simple 'animation' of a 3D plot. See also rotate_axes3d_demo.
43
"""
4+
5+
from __future__ import print_function
6+
57
from mpl_toolkits.mplot3d import axes3d
68
import matplotlib.pyplot as plt
79
import numpy as np
810
import time
911

1012

1113
def generate(X, Y, phi):
14+
'''
15+
Generates Z data for the points in the X, Y meshgrid and parameter phi.
16+
'''
1217
R = 1 - np.sqrt(X**2 + Y**2)
1318
return np.cos(2 * np.pi * X + phi) * R
1419

20+
1521
fig = plt.figure()
1622
ax = fig.add_subplot(111, projection='3d')
1723

24+
# Make the X, Y meshgrid.
1825
xs = np.linspace(-1, 1, 50)
1926
ys = np.linspace(-1, 1, 50)
2027
X, Y = np.meshgrid(xs, ys)
21-
Z = generate(X, Y, 0.0)
2228

29+
# Set the z axis limits so they aren't recalculated each frame.
30+
ax.set_zlim(-1, 1)
31+
32+
# Begin plotting.
2333
wframe = None
2434
tstart = time.time()
25-
for phi in np.linspace(0, 360 / 2 / np.pi, 100):
26-
27-
oldcol = wframe
35+
for phi in np.linspace(0, 180. / np.pi, 100):
36+
# If a line collection is already remove it before drawing.
37+
if wframe:
38+
ax.collections.remove(wframe)
2839

40+
# Plot the new wireframe and pause briefly before continuing.
2941
Z = generate(X, Y, phi)
3042
wframe = ax.plot_wireframe(X, Y, Z, rstride=2, cstride=2)
31-
32-
# Remove old line collection before drawing
33-
if oldcol is not None:
34-
ax.collections.remove(oldcol)
35-
3643
plt.pause(.001)
3744

38-
print('FPS: %f' % (100 / (time.time() - tstart)))
45+
print('Average FPS: %f' % (100 / (time.time() - tstart)))

examples/mplot3d/wire3d_demo.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
'''
2+
A very basic demonstration of a wireframe plot.
3+
'''
4+
15
from mpl_toolkits.mplot3d import axes3d
26
import matplotlib.pyplot as plt
3-
import numpy as np
7+
48

59
fig = plt.figure()
610
ax = fig.add_subplot(111, projection='3d')
11+
12+
# Grab some test data.
713
X, Y, Z = axes3d.get_test_data(0.05)
14+
15+
# Plot a basic wireframe.
816
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
917

1018
plt.show()
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
'''
2+
Demonstrates that setting rstride or cstride to 0 causes wires to not be
3+
generated in the corresponding direction.
4+
'''
5+
16
from mpl_toolkits.mplot3d import axes3d
27
import matplotlib.pyplot as plt
3-
import numpy as np
8+
49

510
fig, [ax1, ax2] = plt.subplots(2, 1, figsize=(8, 12), subplot_kw={'projection': '3d'})
11+
12+
# Get the test data
613
X, Y, Z = axes3d.get_test_data(0.05)
14+
15+
# Give the first plot only wireframes of the type y = c
716
ax1.plot_wireframe(X, Y, Z, rstride=10, cstride=0)
8-
ax1.set_title("Column stride 0")
17+
ax1.set_title("Column (x) stride set to 0")
18+
19+
# Give the second plot only wireframes of the type x = c
920
ax2.plot_wireframe(X, Y, Z, rstride=0, cstride=10)
10-
ax2.set_title("Row stride 0")
21+
ax2.set_title("Row (y) stride set to 0")
22+
1123
plt.tight_layout()
1224
plt.show()

0 commit comments

Comments
 (0)