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

Skip to content

Commit 51642d7

Browse files
committed
Comments and cosmetic changes to mplot3d examples: custom_shaded_3d_surface, lines3d_demo, offset_demo
1 parent 8c73982 commit 51642d7

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

examples/mplot3d/custom_shaded_3d_surface.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
"""
22
Demonstrates using custom hillshading in a 3D surface plot.
33
"""
4+
45
from mpl_toolkits.mplot3d import Axes3D
56
from matplotlib import cbook
67
from matplotlib import cm
78
from matplotlib.colors import LightSource
89
import matplotlib.pyplot as plt
910
import numpy as np
1011

12+
# Load and format data
1113
filename = cbook.get_sample_data('jacksboro_fault_dem.npz', asfileobj=False)
1214
with np.load(filename) as dem:
1315
z = dem['elevation']
@@ -19,6 +21,7 @@
1921
region = np.s_[5:50, 5:50]
2022
x, y, z = x[region], y[region], z[region]
2123

24+
# Set up plot
2225
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
2326

2427
ls = LightSource(270, 45)

examples/mplot3d/lines3d_demo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
'''
2+
Demonstrating plotting a parametric curve in 3D.
3+
'''
4+
15
import matplotlib as mpl
26
from mpl_toolkits.mplot3d import Axes3D
37
import numpy as np
@@ -7,11 +11,14 @@
711

812
fig = plt.figure()
913
ax = fig.gca(projection='3d')
14+
15+
# Prepare arrays x, y, z
1016
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
1117
z = np.linspace(-2, 2, 100)
1218
r = z**2 + 1
1319
x = r * np.sin(theta)
1420
y = r * np.cos(theta)
21+
1522
ax.plot(x, y, z, label='parametric curve')
1623
ax.legend()
1724

examples/mplot3d/offset_demo.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1+
'''
2+
This example demonstrates mplot3d's offset text display.
3+
As one rotates the 3D figure, the offsets should remain oriented the
4+
same way as the axis label, and should also be located "away"
5+
from the center of the plot.
6+
7+
This demo triggers the display of the offset text for the x and
8+
y axis by adding 1e5 to X and Y. Anything less would not
9+
automatically trigger it.
10+
'''
11+
112
from mpl_toolkits.mplot3d import Axes3D
213
import matplotlib.pyplot as plt
314
import numpy as np
415

5-
# This example demonstrates mplot3d's offset text display.
6-
# As one rotates the 3D figure, the offsets should remain oriented
7-
# same way as the axis label, and should also be located "away"
8-
# from the center of the plot.
9-
#
10-
# This demo triggers the display of the offset text for the x and
11-
# y axis by adding 1e5 to X and Y. Anything less would not
12-
# automatically trigger it.
1316

1417
fig = plt.figure()
1518
ax = fig.gca(projection='3d')
19+
1620
X, Y = np.mgrid[0:6*np.pi:0.25, 0:4*np.pi:0.25]
1721
Z = np.sqrt(np.abs(np.cos(X) + np.cos(Y)))
1822

19-
surf = ax.plot_surface(X + 1e5, Y + 1e5, Z, cmap='autumn', cstride=2, rstride=2)
20-
ax.set_xlabel("X-Label")
21-
ax.set_ylabel("Y-Label")
22-
ax.set_zlabel("Z-Label")
23+
ax.plot_surface(X + 1e5, Y + 1e5, Z, cmap='autumn', cstride=2, rstride=2)
24+
25+
ax.set_xlabel("X label")
26+
ax.set_ylabel("Y label")
27+
ax.set_zlabel("Z label")
2328
ax.set_zlim(0, 2)
2429

2530
plt.show()

0 commit comments

Comments
 (0)