Skip to content

Commit b779509

Browse files
authored
Merge pull request #19014 from anntzer/normalize-none
Support normalize_kwargs(None) (== {}).
2 parents f50fe72 + 7ddd1cb commit b779509

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3868,23 +3868,20 @@ def line_props_with_rcdefaults(subkey, explicit, zdelta=0,
38683868
d['zorder'] = zorder + zdelta
38693869
if not use_marker:
38703870
d['marker'] = ''
3871-
if explicit is not None:
3872-
d.update(cbook.normalize_kwargs(explicit, mlines.Line2D))
3871+
d.update(cbook.normalize_kwargs(explicit, mlines.Line2D))
38733872
return d
38743873

38753874
# box properties
38763875
if patch_artist:
3877-
final_boxprops = dict(
3878-
linestyle=rcParams['boxplot.boxprops.linestyle'],
3879-
linewidth=rcParams['boxplot.boxprops.linewidth'],
3880-
edgecolor=rcParams['boxplot.boxprops.color'],
3881-
facecolor=('white' if rcParams['_internal.classic_mode'] else
3882-
rcParams['patch.facecolor']),
3883-
zorder=zorder,
3884-
)
3885-
if boxprops is not None:
3886-
final_boxprops.update(
3887-
cbook.normalize_kwargs(boxprops, mpatches.PathPatch))
3876+
final_boxprops = {
3877+
'linestyle': rcParams['boxplot.boxprops.linestyle'],
3878+
'linewidth': rcParams['boxplot.boxprops.linewidth'],
3879+
'edgecolor': rcParams['boxplot.boxprops.color'],
3880+
'facecolor': ('white' if rcParams['_internal.classic_mode']
3881+
else rcParams['patch.facecolor']),
3882+
'zorder': zorder,
3883+
**cbook.normalize_kwargs(boxprops, mpatches.PathPatch)
3884+
}
38883885
else:
38893886
final_boxprops = line_props_with_rcdefaults('boxprops', boxprops,
38903887
use_marker=False)

lib/matplotlib/cbook/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,8 +1714,10 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
17141714
17151715
Parameters
17161716
----------
1717-
kw : dict
1718-
A dict of keyword arguments.
1717+
kw : dict or None
1718+
A dict of keyword arguments. None is explicitly supported and treated
1719+
as an empty dict, to support functions with an optional parameter of
1720+
the form ``props=None``.
17191721
17201722
alias_mapping : dict or Artist subclass or Artist instance, optional
17211723
A mapping between a canonical name to a list of
@@ -1747,6 +1749,9 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
17471749
"""
17481750
from matplotlib.artist import Artist
17491751

1752+
if kw is None:
1753+
return {}
1754+
17501755
# deal with default value of alias_mapping
17511756
if alias_mapping is None:
17521757
alias_mapping = dict()

lib/matplotlib/tests/test_cbook.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ def test_sanitize_sequence():
309309
)
310310

311311
pass_mapping = (
312+
(None, {}, {}),
312313
({'a': 1, 'b': 2}, {'a': 1, 'b': 2}, {}),
313314
({'b': 2}, {'a': 2}, {'alias_mapping': {'a': ['a', 'b']}}),
314315
({'b': 2}, {'a': 2},

lib/matplotlib/widgets.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,11 +1826,10 @@ class ToolHandles:
18261826

18271827
def __init__(self, ax, x, y, marker='o', marker_props=None, useblit=True):
18281828
self.ax = ax
1829-
props = dict(marker=marker, markersize=7, markerfacecolor='w',
1830-
linestyle='none', alpha=0.5, visible=False,
1831-
label='_nolegend_')
1832-
props.update(cbook.normalize_kwargs(marker_props, Line2D._alias_map)
1833-
if marker_props is not None else {})
1829+
props = {'marker': marker, 'markersize': 7, 'markerfacecolor': 'w',
1830+
'linestyle': 'none', 'alpha': 0.5, 'visible': False,
1831+
'label': '_nolegend_',
1832+
**cbook.normalize_kwargs(marker_props, Line2D._alias_map)}
18341833
self._markers = Line2D(x, y, animated=useblit, **props)
18351834
self.ax.add_line(self._markers)
18361835
self.artist = self._markers
@@ -2000,8 +1999,7 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
20001999
props = dict(markeredgecolor='r')
20012000
else:
20022001
props = dict(markeredgecolor=rectprops.get('edgecolor', 'r'))
2003-
props.update(cbook.normalize_kwargs(marker_props, Line2D._alias_map)
2004-
if marker_props is not None else {})
2002+
props.update(cbook.normalize_kwargs(marker_props, Line2D._alias_map))
20052003
self._corner_order = ['NW', 'NE', 'SE', 'SW']
20062004
xc, yc = self.corners
20072005
self._corner_handles = ToolHandles(self.ax, xc, yc, marker_props=props,

0 commit comments

Comments
 (0)