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

Skip to content

Commit 173c3bf

Browse files
committed
Document contour3d and contourf3d examples
1 parent 51642d7 commit 173c3bf

File tree

5 files changed

+64
-12
lines changed

5 files changed

+64
-12
lines changed

examples/mplot3d/contour3d_demo.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
'''
2+
Demonstrates plotting contour (level) curves in 3D.
3+
4+
This is like a contour plot in 2D except that the f(x,y)=c curve is plotted
5+
on the plane z=c.
6+
'''
7+
18
from mpl_toolkits.mplot3d import axes3d
29
import matplotlib.pyplot as plt
310
from matplotlib import cm
411

512
fig = plt.figure()
6-
ax = fig.add_subplot(111, projection='3d')
13+
ax = fig.gca(projection='3d')
714
X, Y, Z = axes3d.get_test_data(0.05)
15+
16+
# Plot contour curves
817
cset = ax.contour(X, Y, Z, cmap=cm.coolwarm)
18+
919
ax.clabel(cset, fontsize=9, inline=1)
1020

1121
plt.show()

examples/mplot3d/contour3d_demo2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
'''
2+
Demonstrates plotting contour (level) curves in 3D using the extend3d option.
3+
4+
This modification of the contour3d_demo example uses extend3d=True to
5+
extend the curves vertically into 'ribbons'.
6+
'''
7+
18
from mpl_toolkits.mplot3d import axes3d
29
import matplotlib.pyplot as plt
310
from matplotlib import cm
411

512
fig = plt.figure()
613
ax = fig.gca(projection='3d')
714
X, Y, Z = axes3d.get_test_data(0.05)
15+
816
cset = ax.contour(X, Y, Z, extend3d=True, cmap=cm.coolwarm)
17+
918
ax.clabel(cset, fontsize=9, inline=1)
1019

1120
plt.show()

examples/mplot3d/contour3d_demo3.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1+
'''
2+
Demonstrates displaying a 3D surface while also projecting contour 'profiles'
3+
onto the 'walls' of the graph.
4+
5+
See contourf3d_demo2 for the filled version.
6+
'''
7+
18
from mpl_toolkits.mplot3d import axes3d
29
import matplotlib.pyplot as plt
310
from matplotlib import cm
411

512
fig = plt.figure()
613
ax = fig.gca(projection='3d')
714
X, Y, Z = axes3d.get_test_data(0.05)
15+
16+
# Plot the 3D surface
817
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
9-
cset = ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
18+
19+
# Plot projections of the contours for each dimension. By choosing offsets
20+
# that match the appropriate axes limits, the projected contours will sit on
21+
# the 'walls' of the graph
1022
cset = ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
1123
cset = ax.contour(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)
24+
cset = ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
1225

13-
ax.set_xlabel('X')
1426
ax.set_xlim(-40, 40)
15-
ax.set_ylabel('Y')
1627
ax.set_ylim(-40, 40)
17-
ax.set_zlabel('Z')
1828
ax.set_zlim(-100, 100)
1929

30+
ax.set_xlabel('X')
31+
ax.set_ylabel('Y')
32+
ax.set_zlabel('Z')
33+
2034
plt.show()

examples/mplot3d/contourf3d_demo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
'''
2+
contourf differs from contour in that it creates filled contours, ie.
3+
a discrete number of colours are used to shade the domain.
4+
5+
This is like a contourf plot in 2D except that the shaded region corresponding
6+
to the level c is graphed on the plane z=c.
7+
'''
8+
19
from mpl_toolkits.mplot3d import axes3d
210
import matplotlib.pyplot as plt
311
from matplotlib import cm
412

513
fig = plt.figure()
614
ax = fig.gca(projection='3d')
715
X, Y, Z = axes3d.get_test_data(0.05)
16+
817
cset = ax.contourf(X, Y, Z, cmap=cm.coolwarm)
18+
919
ax.clabel(cset, fontsize=9, inline=1)
1020

1121
plt.show()

examples/mplot3d/contourf3d_demo2.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
"""
2-
.. versionadded:: 1.1.0
3-
This demo depends on new features added to contourf3d.
4-
"""
1+
'''
2+
Demonstrates displaying a 3D surface while also projecting filled contour
3+
'profiles' onto the 'walls' of the graph.
4+
5+
See contourf3d_demo2 for the unfilled version.
6+
'''
57

68
from mpl_toolkits.mplot3d import axes3d
79
import matplotlib.pyplot as plt
@@ -10,16 +12,23 @@
1012
fig = plt.figure()
1113
ax = fig.gca(projection='3d')
1214
X, Y, Z = axes3d.get_test_data(0.05)
15+
16+
# Plot the 3D surface
1317
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
18+
19+
# Plot projections of the contours for each dimension. By choosing offsets
20+
# that match the appropriate axes limits, the projected contours will sit on
21+
# the 'walls' of the graph
1422
cset = ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
1523
cset = ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
1624
cset = ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)
1725

18-
ax.set_xlabel('X')
1926
ax.set_xlim(-40, 40)
20-
ax.set_ylabel('Y')
2127
ax.set_ylim(-40, 40)
22-
ax.set_zlabel('Z')
2328
ax.set_zlim(-100, 100)
2429

30+
ax.set_xlabel('X')
31+
ax.set_ylabel('Y')
32+
ax.set_zlabel('Z')
33+
2534
plt.show()

0 commit comments

Comments
 (0)