Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 35ea0fd

Browse filesBrowse files
committed
Document contour3d and contourf3d examples
1 parent ac0edb8 commit 35ea0fd
Copy full SHA for 35ea0fd

File tree

Expand file treeCollapse file tree

5 files changed

+63
-11
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+63
-11
lines changed

‎examples/mplot3d/contour3d_demo.py

Copy file name to clipboard
+11-1Lines 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

Copy file name to clipboard
+9Lines 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

Copy file name to clipboard
+17-3Lines changed: 17 additions & 3 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)
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
922
cset = ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
1023
cset = ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
1124
cset = ax.contour(X, Y, Z, zdir='y', offset=40, 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

Copy file name to clipboard
+10Lines 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

Copy file name to clipboard
+16-7Lines 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 contour3d_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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.