Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0e54b2

Browse files
authored
Merge pull request #24810 from QuLogic/widget-dicts
Don't modify dictionary input to widgets
2 parents ddf33db + 1abd966 commit e0e54b2

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

lib/matplotlib/widgets.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,9 +2729,11 @@ def __init__(self, ax, positions, direction, line_props=None,
27292729
_api.check_in_list(['horizontal', 'vertical'], direction=direction)
27302730
self._direction = direction
27312731

2732-
if line_props is None:
2733-
line_props = {}
2734-
line_props.update({'visible': False, 'animated': useblit})
2732+
line_props = {
2733+
**(line_props if line_props is not None else {}),
2734+
'visible': False,
2735+
'animated': useblit,
2736+
}
27352737

27362738
line_fun = ax.axvline if self.direction == 'horizontal' else ax.axhline
27372739

@@ -3035,9 +3037,8 @@ def __init__(self, ax, onselect, drawtype='box',
30353037
if props is None:
30363038
props = dict(facecolor='red', edgecolor='black',
30373039
alpha=0.2, fill=True)
3038-
props['animated'] = self.useblit
3039-
self._visible = props.pop('visible', self._visible)
3040-
self._props = props
3040+
self._props = {**props, 'animated': self.useblit}
3041+
self._visible = self._props.pop('visible', self._visible)
30413042
to_draw = self._init_shape(**self._props)
30423043
self.ax.add_patch(to_draw)
30433044
if drawtype == 'line':
@@ -3048,8 +3049,7 @@ def __init__(self, ax, onselect, drawtype='box',
30483049
if lineprops is None:
30493050
lineprops = dict(color='black', linestyle='-',
30503051
linewidth=2, alpha=0.5)
3051-
lineprops['animated'] = self.useblit
3052-
self._props = lineprops
3052+
self._props = {**lineprops, 'animated': self.useblit}
30533053
to_draw = Line2D([0, 0], [0, 0], visible=False, **self._props)
30543054
self.ax.add_line(to_draw)
30553055

@@ -3622,10 +3622,12 @@ def __init__(self, ax, onselect=None, useblit=True, props=None,
36223622
button=None):
36233623
super().__init__(ax, onselect, useblit=useblit, button=button)
36243624
self.verts = None
3625-
if props is None:
3626-
props = dict()
3627-
# self.useblit may be != useblit, if the canvas doesn't support blit.
3628-
props.update(animated=self.useblit, visible=False)
3625+
props = {
3626+
**(props if props is not None else {}),
3627+
# Note that self.useblit may be != useblit, if the canvas doesn't
3628+
# support blitting.
3629+
'animated': self.useblit, 'visible': False,
3630+
}
36293631
line = Line2D([], [], **props)
36303632
self.ax.add_line(line)
36313633
self._selection_artist = line
@@ -3760,8 +3762,7 @@ def __init__(self, ax, onselect, useblit=False,
37603762

37613763
if props is None:
37623764
props = dict(color='k', linestyle='-', linewidth=2, alpha=0.5)
3763-
props['animated'] = self.useblit
3764-
self._props = props
3765+
self._props = {**props, 'animated': self.useblit}
37653766
self._selection_artist = line = Line2D([], [], **self._props)
37663767
self.ax.add_line(line)
37673768

0 commit comments

Comments
 (0)