Skip to content

Commit 45071c9

Browse files
committed
BUG: Fix box_handle_props initialization
1 parent 4946ac3 commit 45071c9

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

lib/matplotlib/tests/test_widgets.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,44 @@ def test_polygon_selector_box(ax):
17171717
tool._box.extents, (20.0, 40.0, 30.0, 40.0))
17181718

17191719

1720+
def test_polygon_selector_box_props_handle_props(ax):
1721+
props = dict(color='r')
1722+
handle_props = dict(marker='o', markerfacecolor='w', markeredgecolor='r')
1723+
box_props = dict(linestyle=':', facecolor='c', edgecolor='b')
1724+
box_handle_props = dict(markeredgecolor='y')
1725+
1726+
tool = widgets.PolygonSelector(
1727+
ax, draw_bounding_box=True,
1728+
props=props, handle_props=handle_props,
1729+
box_props=box_props, box_handle_props=box_handle_props)
1730+
1731+
for event in [
1732+
*polygon_place_vertex(ax, (50, 50)),
1733+
*polygon_place_vertex(ax, (150, 50)),
1734+
*polygon_place_vertex(ax, (50, 150)),
1735+
*polygon_place_vertex(ax, (50, 50)),
1736+
]:
1737+
event._process()
1738+
1739+
artist = tool._selection_artist
1740+
assert artist.get_color() == 'r'
1741+
for artist in tool._handles_artists:
1742+
assert artist.get_marker() == 'o'
1743+
assert artist.get_markerfacecolor() == 'w'
1744+
assert artist.get_markeredgecolor() == 'r'
1745+
1746+
box_artist = tool._box._selection_artist
1747+
assert box_artist.get_linestyle() == ':'
1748+
assert box_artist.get_facecolor() == mcolors.to_rgba('c')
1749+
assert box_artist.get_edgecolor() == mcolors.to_rgba('b')
1750+
for artist in tool._box._handles_artists:
1751+
# marker and markerfacecolor are inherited from handle_props
1752+
# markeredgecolor is overridden by box_handle_props.
1753+
assert artist.get_marker() == 'o'
1754+
assert artist.get_markerfacecolor() == 'w'
1755+
assert artist.get_markeredgecolor() == 'y'
1756+
1757+
17201758
def test_polygon_selector_clear_method(ax):
17211759
onselect = mock.Mock(spec=noop, return_value=None)
17221760
tool = widgets.PolygonSelector(ax, onselect)

lib/matplotlib/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4118,7 +4118,7 @@ def __init__(self, ax, onselect=None, *, useblit=False,
41184118

41194119
if box_handle_props is None:
41204120
box_handle_props = {}
4121-
self._box_handle_props = self._handle_props.update(box_handle_props)
4121+
self._box_handle_props = {**self._handle_props, **box_handle_props}
41224122
self._box_props = box_props
41234123

41244124
def _get_bbox(self):

0 commit comments

Comments
 (0)