Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,44 @@ def test_polygon_selector_box(ax):
tool._box.extents, (20.0, 40.0, 30.0, 40.0))


def test_polygon_selector_box_props_handle_props(ax):
props = dict(color='r')
handle_props = dict(marker='o', markerfacecolor='w', markeredgecolor='r')
box_props = dict(linestyle=':', facecolor='c', edgecolor='b')
box_handle_props = dict(markeredgecolor='y')

tool = widgets.PolygonSelector(
ax, draw_bounding_box=True,
props=props, handle_props=handle_props,
box_props=box_props, box_handle_props=box_handle_props)

for event in [
*polygon_place_vertex(ax, (50, 50)),
*polygon_place_vertex(ax, (150, 50)),
*polygon_place_vertex(ax, (50, 150)),
*polygon_place_vertex(ax, (50, 50)),
]:
event._process()

artist = tool._selection_artist
assert mcolors.same_color(artist.get_color(), 'r')
for artist in tool._handles_artists:
assert artist.get_marker() == 'o'
assert mcolors.same_color(artist.get_markerfacecolor(), 'w')
assert mcolors.same_color(artist.get_markeredgecolor(), 'r')

box_artist = tool._box._selection_artist
assert box_artist.get_linestyle() == ':'
assert box_artist.get_facecolor() == mcolors.to_rgba('c')
assert box_artist.get_edgecolor() == mcolors.to_rgba('b')
for artist in tool._box._handles_artists:
# marker and markerfacecolor are inherited from handle_props
# markeredgecolor is overridden by box_handle_props.
assert artist.get_marker() == 'o'
assert mcolors.same_color(artist.get_markerfacecolor(), 'w')
assert mcolors.same_color(artist.get_markeredgecolor(), 'y')


def test_polygon_selector_clear_method(ax):
onselect = mock.Mock(spec=noop, return_value=None)
tool = widgets.PolygonSelector(ax, onselect)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4118,7 +4118,7 @@ def __init__(self, ax, onselect=None, *, useblit=False,

if box_handle_props is None:
box_handle_props = {}
self._box_handle_props = self._handle_props.update(box_handle_props)
self._box_handle_props = {**self._handle_props, **box_handle_props}
self._box_props = box_props

def _get_bbox(self):
Expand Down
Loading