|
5 | 5 | from numpy.testing import assert_array_equal
|
6 | 6 | import pytest
|
7 | 7 |
|
| 8 | +from matplotlib import patches |
8 | 9 | from matplotlib.path import Path
|
9 | 10 | from matplotlib.patches import Polygon
|
10 | 11 | from matplotlib.testing.decorators import image_comparison
|
11 | 12 | import matplotlib.pyplot as plt
|
12 | 13 | from matplotlib import transforms
|
| 14 | +from matplotlib.backend_bases import MouseEvent |
13 | 15 |
|
14 | 16 |
|
15 | 17 | def test_empty_closed_path():
|
@@ -70,6 +72,46 @@ def test_nonlinear_containment():
|
70 | 72 | ax.transData.transform_point((50, .5)), ax.transData)
|
71 | 73 |
|
72 | 74 |
|
| 75 | +@image_comparison( |
| 76 | + baseline_images=['arrow_contains_point'], extensions=['png'], |
| 77 | + remove_text=True, style='mpl20') |
| 78 | +def test_arrow_contains_point(): |
| 79 | + # fix bug (#8384) |
| 80 | + fig, ax = plt.subplots() |
| 81 | + ax.set_xlim((0, 2)) |
| 82 | + ax.set_ylim((0, 2)) |
| 83 | + |
| 84 | + # create an arrow with Curve style |
| 85 | + arrow = patches.FancyArrowPatch((0.5, 0.25), (1.5, 0.75), |
| 86 | + arrowstyle='->', |
| 87 | + mutation_scale=40) |
| 88 | + ax.add_patch(arrow) |
| 89 | + # create an arrow with Bracket style |
| 90 | + arrow1 = patches.FancyArrowPatch((0.5, 1), (1.5, 1.25), |
| 91 | + arrowstyle=']-[', |
| 92 | + mutation_scale=40) |
| 93 | + ax.add_patch(arrow1) |
| 94 | + # create an arrow with other arrow style |
| 95 | + arrow2 = patches.FancyArrowPatch((0.5, 1.5), (1.5, 1.75), |
| 96 | + arrowstyle='fancy', |
| 97 | + fill=False, |
| 98 | + mutation_scale=40) |
| 99 | + ax.add_patch(arrow2) |
| 100 | + patches_list = [arrow, arrow1, arrow2] |
| 101 | + |
| 102 | + # generate some points |
| 103 | + X, Y = np.meshgrid(np.arange(0, 2, 0.1), |
| 104 | + np.arange(0, 2, 0.1)) |
| 105 | + for k, (x, y) in enumerate(zip(X.ravel(), Y.ravel())): |
| 106 | + xdisp, ydisp = ax.transData.transform_point([x, y]) |
| 107 | + event = MouseEvent('button_press_event', fig.canvas, xdisp, ydisp) |
| 108 | + for m, patch in enumerate(patches_list): |
| 109 | + # set the points to red only if the arrow contains the point |
| 110 | + inside, res = patch.contains(event) |
| 111 | + if inside: |
| 112 | + ax.scatter(x, y, s=5, c="r") |
| 113 | + |
| 114 | + |
73 | 115 | @image_comparison(baseline_images=['path_clipping'],
|
74 | 116 | extensions=['svg'], remove_text=True)
|
75 | 117 | def test_path_clipping():
|
|
0 commit comments