6
6
import pytest
7
7
8
8
import matplotlib
9
+ from matplotlib .backend_bases import MouseEvent
9
10
import matplotlib .patches as mpatches
10
11
import matplotlib .pyplot as plt
11
12
from matplotlib .testing .decorators import image_comparison
@@ -204,13 +205,10 @@ def test_afm_kerning():
204
205
205
206
@image_comparison (baseline_images = ['text_contains' ], extensions = ['png' ])
206
207
def test_contains ():
207
- import matplotlib .backend_bases as mbackend
208
-
209
208
fig = plt .figure ()
210
209
ax = plt .axes ()
211
210
212
- mevent = mbackend .MouseEvent (
213
- 'button_press_event' , fig .canvas , 0.5 , 0.5 , 1 , None )
211
+ mevent = MouseEvent ('button_press_event' , fig .canvas , 0.5 , 0.5 , 1 , None )
214
212
215
213
xs = np .linspace (0.25 , 0.75 , 30 )
216
214
ys = np .linspace (0.25 , 0.75 , 30 )
@@ -236,6 +234,19 @@ def test_contains():
236
234
ax .viewLim .set (vl )
237
235
238
236
237
+ def test_annotation_contains ():
238
+ # Check that Annotation.contains looks at the bboxes of the text and the
239
+ # arrow separately, not at the joint bbox.
240
+ fig , ax = plt .subplots ()
241
+ ann = ax .annotate (
242
+ "hello" , xy = (.4 , .4 ), xytext = (.6 , .6 ), arrowprops = {"arrowstyle" : "->" })
243
+ fig .canvas .draw () # Needed for the same reason as in test_contains.
244
+ event = MouseEvent (
245
+ "button_press_event" , fig .canvas ,
246
+ * ax .transData .transform_point ((.5 , .6 )))
247
+ assert ann .contains (event ) == (False , {})
248
+
249
+
239
250
@image_comparison (baseline_images = ['titles' ])
240
251
def test_titles ():
241
252
# left and right side titles
0 commit comments