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

Commit0611b61

Browse files
authored
Merge pull request#7844 from anntzer/nonlinear-transformed-path-containment
Fix containment test with nonlinear transforms.
2 parentsf238c58 +76173e1 commit0611b61

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

‎lib/matplotlib/path.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
importnumpyasnp
2424

25-
frommatplotlibimport_path
26-
frommatplotlib.cbookimportsimple_linear_interpolation,maxdict
27-
frommatplotlibimportrcParams
25+
from .import_path,rcParams
26+
from .cbookimportsimple_linear_interpolation,maxdict
2827

2928

3029
classPath(object):
@@ -493,9 +492,14 @@ def contains_point(self, point, transform=None, radius=0.0):
493492
"""
494493
iftransformisnotNone:
495494
transform=transform.frozen()
496-
result=_path.point_in_path(point[0],point[1],radius,self,
497-
transform)
498-
returnresult
495+
# `point_in_path` does not handle nonlinear transforms, so we
496+
# transform the path ourselves. If `transform` is affine, letting
497+
# `point_in_path` handle the transform avoids allocating an extra
498+
# buffer.
499+
iftransformandnottransform.is_affine:
500+
self=transform.transform_path(self)
501+
transform=None
502+
return_path.point_in_path(point[0],point[1],radius,self,transform)
499503

500504
defcontains_points(self,points,transform=None,radius=0.0):
501505
"""

‎lib/matplotlib/tests/test_path.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ def test_contains_points_negative_radius():
4545
assertnp.all(result==expected)
4646

4747

48+
deftest_point_in_path_nan():
49+
box=np.array([[0,0], [1,0], [1,1], [0,1], [0,0]])
50+
p=Path(box)
51+
test=np.array([[np.nan,0.5]])
52+
contains=p.contains_points(test)
53+
assertlen(contains)==1
54+
assertnotcontains[0]
55+
56+
57+
deftest_nonlinear_containment():
58+
fig,ax=plt.subplots()
59+
ax.set(xscale="log",ylim=(0,1))
60+
polygon=ax.axvspan(1,10)
61+
assertpolygon.get_path().contains_point(
62+
ax.transData.transform_point((5,.5)),ax.transData)
63+
assertnotpolygon.get_path().contains_point(
64+
ax.transData.transform_point((.5,.5)),ax.transData)
65+
assertnotpolygon.get_path().contains_point(
66+
ax.transData.transform_point((50,.5)),ax.transData)
67+
68+
4869
@image_comparison(baseline_images=['path_clipping'],
4970
extensions=['svg'],remove_text=True)
5071
deftest_path_clipping():
@@ -66,15 +87,6 @@ def test_path_clipping():
6687
xy,facecolor='none',edgecolor='red',closed=True))
6788

6889

69-
deftest_point_in_path_nan():
70-
box=np.array([[0,0], [1,0], [1,1], [0,1], [0,0]])
71-
p=Path(box)
72-
test=np.array([[np.nan,0.5]])
73-
contains=p.contains_points(test)
74-
assertlen(contains)==1
75-
assertnotcontains[0]
76-
77-
7890
@image_comparison(baseline_images=['semi_log_with_zero'],extensions=['png'])
7991
deftest_log_transform_with_zero():
8092
x=np.arange(-10,10)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp