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

Function test_polygon_selector_box

lib/matplotlib/tests/test_widgets.py:1677–1717  ·  view source on GitHub ↗
(ax)

Source from the content-addressed store, hash-verified

1675
1676
1677def test_polygon_selector_box(ax):
1678 # Create a diamond (adjusting axes lims s.t. the diamond lies within axes limits).
1679 ax.set(xlim=(-10, 50), ylim=(-10, 50))
1680 verts = [(20, 0), (0, 20), (20, 40), (40, 20)]
1681 event_sequence = [
1682 *polygon_place_vertex(ax, verts[0]),
1683 *polygon_place_vertex(ax, verts[1]),
1684 *polygon_place_vertex(ax, verts[2]),
1685 *polygon_place_vertex(ax, verts[3]),
1686 *polygon_place_vertex(ax, verts[0]),
1687 ]
1688
1689 # Create selector
1690 tool = widgets.PolygonSelector(ax, draw_bounding_box=True)
1691 for event in event_sequence:
1692 event._process()
1693
1694 # Scale to half size using the top right corner of the bounding box
1695 MouseEvent._from_ax_coords("button_press_event", ax, (40, 40), 1)._process()
1696 MouseEvent._from_ax_coords("motion_notify_event", ax, (20, 20))._process()
1697 MouseEvent._from_ax_coords("button_release_event", ax, (20, 20), 1)._process()
1698 np.testing.assert_allclose(
1699 tool.verts, [(10, 0), (0, 10), (10, 20), (20, 10)])
1700
1701 # Move using the center of the bounding box
1702 MouseEvent._from_ax_coords("button_press_event", ax, (10, 10), 1)._process()
1703 MouseEvent._from_ax_coords("motion_notify_event", ax, (30, 30))._process()
1704 MouseEvent._from_ax_coords("button_release_event", ax, (30, 30), 1)._process()
1705 np.testing.assert_allclose(
1706 tool.verts, [(30, 20), (20, 30), (30, 40), (40, 30)])
1707
1708 # Remove a point from the polygon and check that the box extents update
1709 np.testing.assert_allclose(
1710 tool._box.extents, (20.0, 40.0, 20.0, 40.0))
1711
1712 MouseEvent._from_ax_coords("button_press_event", ax, (30, 20), 3)._process()
1713 MouseEvent._from_ax_coords("button_release_event", ax, (30, 20), 3)._process()
1714 np.testing.assert_allclose(
1715 tool.verts, [(20, 30), (30, 40), (40, 30)])
1716 np.testing.assert_allclose(
1717 tool._box.extents, (20.0, 40.0, 30.0, 40.0))
1718
1719
1720def test_polygon_selector_box_props_handle_props(ax):

Callers

nothing calls this directly

Calls 4

polygon_place_vertexFunction · 0.85
_processMethod · 0.80
setMethod · 0.45
_from_ax_coordsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…