Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9dceafc

Browse files
authored
Merge pull request#27349 from scottshambaugh/3d_dynamic_masking
[ENH] Implement dynamic clipping to axes limits for 3D plots
2 parents54d718e +cc5e8d5 commit9dceafc

File tree

9 files changed

+448
-105
lines changed

9 files changed

+448
-105
lines changed

‎doc/missing-references.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@
328328
"lib/matplotlib/quiver.py:docstring of matplotlib.quiver.Barbs:212",
329329
"lib/matplotlib/quiver.py:docstring of matplotlib.quiver.Quiver:251",
330330
"lib/mpl_toolkits/mplot3d/art3d.py:docstring of matplotlib.artist.Path3DCollection.set:46",
331-
"lib/mpl_toolkits/mplot3d/art3d.py:docstring of matplotlib.artist.Poly3DCollection.set:44"
331+
"lib/mpl_toolkits/mplot3d/art3d.py:docstring of matplotlib.artist.Poly3DCollection.set:45"
332332
],
333333
"matplotlib.collections._MeshData.set_array": [
334334
"lib/matplotlib/axes/_axes.py:docstring of matplotlib.axes._axes.Axes.pcolormesh:164",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Data in 3D plots can now be dynamically clipped to the axes view limits
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
All 3D plotting functions now support the *axlim_clip* keyword argument, which
5+
will clip the data to the axes view limits, hiding all data outside those
6+
bounds. This clipping will be dynamically applied in real time while panning
7+
and zooming.
8+
9+
Please note that if one vertex of a line segment or 3D patch is clipped, then
10+
the entire segment or patch will be hidden. Not being able to show partial
11+
lines or patches such that they are "smoothly" cut off at the boundaries of the
12+
view box is a limitation of the current renderer.
13+
14+
..plot::
15+
:include-source: true
16+
:alt: Example of default behavior (left) and axlim_clip=True (right)
17+
18+
import matplotlib.pyplot as plt
19+
import numpy as np
20+
21+
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
22+
np.random.seed(1)
23+
xyz = np.random.rand(25, 3)
24+
25+
# Note that when a line has one vertex outside the view limits, the entire
26+
# 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+
ax.legend(['axlim_clip=False (default)', 'axlim_clip=True'])
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
=====================================
3+
Clip the data to the axes view limits
4+
=====================================
5+
6+
Demonstrate clipping of line and marker data to the axes view limits. The
7+
``axlim_clip`` keyword argument can be used in any of the 3D plotting
8+
functions.
9+
"""
10+
11+
importmatplotlib.pyplotasplt
12+
importnumpyasnp
13+
14+
fig,ax=plt.subplots(subplot_kw={"projection":"3d"})
15+
16+
# Generate the random data
17+
np.random.seed(1)
18+
xyz=np.random.rand(25,3)
19+
20+
# Default behavior is axlim_clip=False
21+
ax.plot(xyz[:,0],xyz[:,1],xyz[:,2],'-o')
22+
23+
# When axlim_clip=True, note that when a line segment has one vertex outside
24+
# the view limits, the entire line is hidden. The same is true for 3D patches
25+
# if one of their vertices is outside the limits (not shown).
26+
ax.plot(xyz[:,0],xyz[:,1],xyz[:,2],'--*',axlim_clip=True)
27+
28+
ax.set(xlim=(0.25,0.75),ylim=(0,1),zlim=(-1,1))
29+
ax.legend(['axlim_clip=False (default)','axlim_clip=True'])
30+
31+
plt.show()

‎galleries/users_explain/toolkits/mplot3d.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ See `.Axes3D.fill_between` for API documentation.
121121
:target:/gallery/mplot3d/fillbetween3d.html
122122
:align:center
123123

124+
..versionadded::3.10
125+
124126
.. _polygon3d:
125127

126128
Polygon plots

‎lib/matplotlib/text.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,16 @@ def draw(self, renderer):
754754

755755
# don't use self.get_position here, which refers to text
756756
# position in Text:
757-
posx=float(self.convert_xunits(self._x))
758-
posy=float(self.convert_yunits(self._y))
757+
x,y=self._x,self._y
758+
ifnp.ma.is_masked(x):
759+
x=np.nan
760+
ifnp.ma.is_masked(y):
761+
y=np.nan
762+
posx=float(self.convert_xunits(x))
763+
posy=float(self.convert_yunits(y))
759764
posx,posy=trans.transform((posx,posy))
765+
ifnp.isnan(posx)ornp.isnan(posy):
766+
return# don't throw a warning here
760767
ifnotnp.isfinite(posx)ornotnp.isfinite(posy):
761768
_log.warning("posx and posy should be finite values")
762769
return

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp