8000 Normalize properties passed to ToolHandles. · QuLogic/matplotlib@5101afe · GitHub
[go: up one dir, main page]

Skip to content

Commit 5101afe

Browse files
committed
Normalize properties passed to ToolHandles.
These can come in through with `RectangleSelector` or `PolygonSelector`, which also need normalization as they have defaults that could be overridden. Fixes matplotlib#12027.
1 parent bd765e0 commit 5101afe

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import matplotlib.colors as mcolors
12
import matplotlib.widgets as widgets
23
import matplotlib.pyplot as plt
34
from matplotlib.testing.decorators import image_comparison
@@ -105,7 +106,9 @@ def onselect(epress, erelease):
105106
pass
106107

107108
tool = widgets.RectangleSelector(ax, onselect=onselect,
108-
maxdist=10, interactive=True)
109+
maxdist=10, interactive=True,
110+
marker_props={'markerfacecolor': 'r',
111+
'markeredgecolor': 'b'})
109112
tool.extents = (100, 150, 100, 150)
110113

111114
assert tool.corners == (
@@ -133,6 +136,12 @@ def onselect(epress, erelease):
133136
do_event(tool, 'release', xdata=100, ydata=100)
134137
assert tool.extents == (10, 100, 10, 100)
135138

139+
# Check that marker_props worked.
140+
assert mcolors.same_color(
141+
tool._corner_handles.artist.get_markerfacecolor(), 'r')
142+
assert mcolors.same_color(
143+
tool._corner_handles.artist.get_markeredgecolor(), 'b')
144+
136145

137146
def check_span(*args, **kwargs):
138147
ax = get_ax()

lib/matplotlib/widgets.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,9 +1855,11 @@ class ToolHandles:
18551855

18561856
def __init__(self, ax, x, y, marker='o', marker_props=None, useblit=True):
18571857
self.ax = ax
1858-
props = dict(marker=marker, markersize=7, mfc='w', ls='none',
1859-
alpha=0.5, visible=False, label='_nolegend_')
1860-
props.update(marker_props if marker_props is not None else {})
1858+
props = dict(marker=marker, markersize=7, markerfacecolor='w',
1859+
linestyle='none', alpha=0.5, visible=False,
1860+
label='_nolegend_')
1861+
props.update(cbook.normalize_kwargs(marker_props, Line2D._alias_map)
1862+
if marker_props is not None else {})
18611863
self._markers = Line2D(x, y, animated=useblit, **props)
18621864
self.ax.add_line(self._markers)
18631865
self.artist = self._markers
@@ -2024,9 +2026,11 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
20242026
self.maxdist = maxdist
20252027

20262028
if rectprops is None:
2027-
props = dict(mec='r')
2029+
props = dict(markeredgecolor='r')
20282030
else:
2029-
props = dict(mec=rectprops.get('edgecolor', 'r'))
2031+
props = dict(markeredgecolor=rectprops.get('edgecolor', 'r'))
2032+
props.update(cbook.normalize_kwargs(marker_props, Line2D._alias_map)
2033+
if marker_props is not None else {})
20302034
self._corner_order = ['NW', 'NE', 'SE', 'SW']
20312035
xc, yc = self.corners
20322036
self._corner_handles = ToolHandles(self.ax, xc, yc, marker_props=props,
@@ -2503,7 +2507,8 @@ def __init__(self, ax, onselect, useblit=False,
25032507
self.ax.add_line(self.line)
25042508

25052509
if markerprops is None:
2506-
markerprops = dict(mec='k', mfc=lineprops.get('color', 'k'))
2510+
markerprops = dict(markeredgecolor='k',
2511+
markerfacecolor=lineprops.get('color', 'k'))
25072512
self._polygon_handles = ToolHandles(self.ax, self._xs, self._ys,
25082513
useblit=self.useblit,
25092514
marker_props=markerprops)

0 commit comments

Comments
 (0)
0