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

Skip to content

Commit e552b5e

Browse files
committed
Documentation and cosmetic changes to mixed_subplots_demo and pathpatch3d_demo
1 parent 173c3bf commit e552b5e

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
2-
Demonstrate the mixing of 2d and 3d subplots
2+
Demonstrate the mixing of 2d and 3d subplots.
33
"""
4+
45
from mpl_toolkits.mplot3d import Axes3D
56
import matplotlib.pyplot as plt
67
import numpy as np
@@ -12,38 +13,42 @@ def f(t):
1213
return np.multiply(s1, e1)
1314

1415

15-
################
16+
#############################################
17+
# Set up a figure twice as tall as it is wide
18+
#############################################
19+
fig = plt.figure(figsize=plt.figaspect(2.))
20+
fig.suptitle('A tale of 2 subplots')
21+
22+
23+
#############################################
1624
# First subplot
17-
################
25+
#############################################
26+
ax = fig.add_subplot(2, 1, 1)
27+
1828
t1 = np.arange(0.0, 5.0, 0.1)
1929
t2 = np.arange(0.0, 5.0, 0.02)
2030
t3 = np.arange(0.0, 2.0, 0.01)
2131

22-
# Twice as tall as it is wide.
23-
fig = plt.figure(figsize=plt.figaspect(2.))
24-
fig.suptitle('A tale of 2 subplots')
25-
ax = fig.add_subplot(2, 1, 1)
26-
l = ax.plot(t1, f(t1), 'bo',
27-
t2, f(t2), 'k--', markerfacecolor='green')
32+
ax.plot(t1, f(t1), 'bo',
33+
t2, f(t2), 'k--', markerfacecolor='green')
2834
ax.grid(True)
2935
ax.set_ylabel('Damped oscillation')
3036

3137

32-
#################
38+
#############################################
3339
# Second subplot
34-
#################
40+
#############################################
3541
ax = fig.add_subplot(2, 1, 2, projection='3d')
42+
3643
X = np.arange(-5, 5, 0.25)
37-
xlen = len(X)
3844
Y = np.arange(-5, 5, 0.25)
39-
ylen = len(Y)
4045
X, Y = np.meshgrid(X, Y)
4146
R = np.sqrt(X**2 + Y**2)
4247
Z = np.sin(R)
4348

4449
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
4550
linewidth=0, antialiased=False)
46-
4751
ax.set_zlim3d(-1, 1)
4852

53+
4954
plt.show()

examples/mplot3d/pathpatch3d_demo.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
'''
2+
Demonstrate using pathpatch_2d_to_3d to 'draw' shapes and text on a 3D plot.
3+
'''
4+
15
import matplotlib.pyplot as plt
26
from matplotlib.patches import Circle, PathPatch
37
# register Axes3D class with matplotlib by importing Axes3D
@@ -8,7 +12,15 @@
812

913

1014
def text3d(ax, xyz, s, zdir="z", size=None, angle=0, usetex=False, **kwargs):
15+
'''
16+
Plots the string 's' on the axes 'ax', with position 'xyz', size 'size',
17+
and rotation angle 'angle'. 'zdir' gives the axis which is to be treated
18+
as the third dimension. usetex is a boolean indicating whether the string
19+
should be interpreted as latex or not. Any additional keyword arguments
20+
are passed on to transform_path.
1121
22+
Note: zdir affects the interpretation of xyz.
23+
'''
1224
x, y, z = xyz
1325
if zdir == "y":
1426
xy1, z1 = (x, z), y
@@ -28,18 +40,20 @@ def text3d(ax, xyz, s, zdir="z", size=None, angle=0, usetex=False, **kwargs):
2840
fig = plt.figure()
2941
ax = fig.add_subplot(111, projection='3d')
3042

43+
# Draw a circle on the x=0 'wall'
3144
p = Circle((5, 5), 3)
3245
ax.add_patch(p)
3346
art3d.pathpatch_2d_to_3d(p, z=0, zdir="x")
3447

35-
48+
# Manually label the axes
3649
text3d(ax, (4, -2, 0), "X-axis", zdir="z", size=.5, usetex=False,
3750
ec="none", fc="k")
3851
text3d(ax, (12, 4, 0), "Y-axis", zdir="z", size=.5, usetex=False,
3952
angle=.5*3.14159, ec="none", fc="k")
4053
text3d(ax, (12, 10, 4), "Z-axis", zdir="y", size=.5, usetex=False,
4154
angle=.5*3.14159, ec="none", fc="k")
4255

56+
# Write a Latex formula on the z=0 'floor'
4357
text3d(ax, (1, 5, 0),
4458
r"$\displaystyle G_{\mu\nu} + \Lambda g_{\mu\nu} = "
4559
r"\frac{8\pi G}{c^4} T_{\mu\nu} $",

0 commit comments

Comments
 (0)