Skip to content

Commit 5a56329

Browse files
Better example for 3D axlim_clip argument
1 parent 25a05f2 commit 5a56329

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

doc/users/next_whats_new/3d_clip_to_axis_limits.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ view box is a limitation of the current renderer.
1313

1414
.. plot::
1515
:include-source: true
16-
:alt: Example of default behavior (left) and axlim_clip=True (right)
16+
:alt: Example of default behavior (blue) and axlim_clip=True (orange)
1717

1818
import matplotlib.pyplot as plt
1919
import numpy as np
2020

2121
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
22-
np.random.seed(1)
23-
xyz = np.random.rand(25, 3)
22+
X = np.arange(-5, 5, 0.5)
23+
Y = np.arange(-5, 5, 0.5)
24+
X, Y = np.meshgrid(X, Y)
25+
R = np.sqrt(X**2 + Y**2)
26+
Z = np.sin(R)
2427

2528
# Note that when a line has one vertex outside the view limits, the entire
2629
# line is hidden. The same is true for 3D patches (not shown).
27-
ax.plot(xyz[:, 0], xyz[:, 1], xyz[:, 2], '-o')
28-
ax.plot(xyz[:, 0], xyz[:, 1], xyz[:, 2], '--*', axlim_clip=True)
29-
ax.set(xlim=(0.25, 0.75), ylim=(0, 1), zlim=(0, 1))
30+
# In this example, data where x < 0 or z > 0.5 will be clipped.
31+
ax.plot_wireframe(X, Y, Z, color='C0')
32+
ax.plot_wireframe(X, Y, Z, color='C1', axlim_clip=True)
33+
ax.set(xlim=(0, 10), ylim=(-5, 5), zlim=(-1, 0.5))
3034
ax.legend(['axlim_clip=False (default)', 'axlim_clip=True'])

galleries/examples/mplot3d/axlim_clip.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@
1313

1414
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
1515

16-
# Generate the random data
17-
np.random.seed(1)
18-
xyz = np.random.rand(25, 3)
16+
# Make the data
17+
X = np.arange(-5, 5, 0.5)
18+
Y = np.arange(-5, 5, 0.5)
19+
X, Y = np.meshgrid(X, Y)
20+
R = np.sqrt(X**2 + Y**2)
21+
Z = np.sin(R)
1922

2023
# Default behavior is axlim_clip=False
21-
ax.plot(xyz[:, 0], xyz[:, 1], xyz[:, 2], '-o')
24+
ax.plot_wireframe(X, Y, Z, color='C0')
2225

2326
# When axlim_clip=True, note that when a line segment has one vertex outside
2427
# the view limits, the entire line is hidden. The same is true for 3D patches
2528
# if one of their vertices is outside the limits (not shown).
26-
ax.plot(xyz[:, 0], xyz[:, 1], xyz[:, 2], '--*', axlim_clip=True)
29+
ax.plot_wireframe(X, Y, Z, color='C1', axlim_clip=True)
2730

28-
ax.set(xlim=(0.25, 0.75), ylim=(0, 1), zlim=(-1, 1))
31+
# In this example, data where x < 0 or z > 0.5 will be clipped.
32+
ax.set(xlim=(0, 10), ylim=(-5, 5), zlim=(-1, 0.5))
2933
ax.legend(['axlim_clip=False (default)', 'axlim_clip=True'])
3034

3135
plt.show()

0 commit comments

Comments
 (0)