Skip to content

Commit da25853

Browse files
authored
Merge pull request matplotlib#22161 from dstansby/polygon-verts-box
FIX: Add box when setting `PolygonSelector.verts`
2 parents d100c42 + 6b7f539 commit da25853

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,17 +1373,20 @@ def test_polygon_selector_redraw(ax, draw_bounding_box):
13731373
assert tool.verts == verts[0:2]
13741374

13751375

1376-
@check_figures_equal()
1377-
def test_polygon_selector_verts_setter(fig_test, fig_ref):
1376+
@pytest.mark.parametrize('draw_bounding_box', [False, True])
1377+
@check_figures_equal(extensions=['png'])
1378+
def test_polygon_selector_verts_setter(fig_test, fig_ref, draw_bounding_box):
13781379
verts = [(0.1, 0.4), (0.5, 0.9), (0.3, 0.2)]
13791380
ax_test = fig_test.add_subplot()
13801381

1381-
tool_test = widgets.PolygonSelector(ax_test, onselect=noop)
1382+
tool_test = widgets.PolygonSelector(
1383+
ax_test, onselect=noop, draw_bounding_box=draw_bounding_box)
13821384
tool_test.verts = verts
13831385
assert tool_test.verts == verts
13841386

13851387
ax_ref = fig_ref.add_subplot()
1386-
tool_ref = widgets.PolygonSelector(ax_ref, onselect=noop)
1388+
tool_ref = widgets.PolygonSelector(
1389+
ax_ref, onselect=noop, draw_bounding_box=draw_bounding_box)
13871390
event_sequence = (polygon_place_vertex(*verts[0]) +
13881391
polygon_place_vertex(*verts[1]) +
13891392
polygon_place_vertex(*verts[2]) +

lib/matplotlib/widgets.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,6 +3910,8 @@ def verts(self, xys):
39103910
self._xys = [*xys, xys[0]]
39113911
self._selection_completed = True
39123912
self.set_visible(True)
3913+
if self._draw_box and self._box is None:
3914+
self._add_box()
39133915
self._draw_polygon()
39143916

39153917

0 commit comments

Comments
 (0)