8000 Fix containment test with nonlinear transforms. by anntzer · Pull Request #7844 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix containment test with nonlinear transforms. #7844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Test path containment w/ nonlin. transforms; group containment tests.
  • Loading branch information
anntzer committed Mar 19, 2017
commit 76173e1aae1a6f92e0e0deba00cd156edfa6ba83
30 changes: 21 additions & 9 deletions lib/matplotlib/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ def test_contains_points_negative_radius():
assert np.all(result == expected)


def test_point_in_path_nan():
box = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
p = Path(box)
test = np.array([[np.nan, 0.5]])
contains = p.contains_points(test)
assert len(contains) == 1
assert not contains[0]


def test_nonlinear_containment():
fig, ax = plt.subplots()
ax.set(xscale="log", ylim=(0, 1))
polygon = ax.axvspan(1, 10)
assert polygon.get_path().contains_point(
ax.transData.transform_point((5, .5)), ax.transData)
assert not polygon.get_path().contains_point(
ax.transData.transform_point((.5, .5)), ax.transData)
assert not polygon.get_path().contains_point(
ax.transData.transform_point((50, .5)), ax.transData)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May also be worth checking that the points (0.5, 0.5) and (20, 0.5) are not inside polygon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


@image_comparison(baseline_images=['path_clipping'],
extensions=['svg'], remove_text=True)
def test_path_clipping():
Expand All @@ -66,15 +87,6 @@ def test_path_clipping():
xy, facecolor='none', edgecolor='red', closed=True))


def test_point_in_path_nan():
box = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
p = Path(box)
test = np.array([[np.nan, 0.5]])
contains = p.contains_points(test)
assert len(contains) == 1
assert not contains[0]


@image_comparison(baseline_images=['semi_log_with_zero'], extensions=['png'])
def test_log_transform_with_zero():
x = np.arange(-10, 10)
Expand Down
0