MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_contains

Function test_contains

lib/matplotlib/tests/test_text.py:211–238  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

209
210@image_comparison(['text_contains.png'], style='mpl20')
211def test_contains():
212 fig = plt.figure(figsize=(8, 6))
213 ax = plt.axes()
214
215 mevent = MouseEvent('button_press_event', fig.canvas, 0.5, 0.5, 1, None)
216
217 xs = np.linspace(0.25, 0.75, 30)
218 ys = np.linspace(0.25, 0.75, 30)
219 xs, ys = np.meshgrid(xs, ys)
220
221 txt = plt.text(
222 0.5, 0.4, 'hello world', ha='center', fontsize=30, rotation=30)
223 # uncomment to draw the text's bounding box
224 # txt.set_bbox(dict(edgecolor='black', facecolor='none'))
225
226 # draw the text. This is important, as the contains method can only work
227 # when a renderer exists.
228 fig.canvas.draw()
229
230 for x, y in zip(xs.flat, ys.flat):
231 mevent.x, mevent.y = plt.gca().transAxes.transform([x, y])
232 contains, _ = txt.contains(mevent)
233 color = 'yellow' if contains else 'red'
234
235 # capture the viewLim, plot a point, and reset the viewLim
236 vl = ax.viewLim.frozen()
237 ax.plot(x, y, 'o', color=color)
238 ax.viewLim.set(vl)
239
240
241def test_annotation_contains():

Callers

nothing calls this directly

Calls 11

MouseEventClass · 0.90
figureMethod · 0.80
gcaMethod · 0.80
axesMethod · 0.45
textMethod · 0.45
drawMethod · 0.45
transformMethod · 0.45
containsMethod · 0.45
frozenMethod · 0.45
plotMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…