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

Skip to content

Commit 6f6ba29

Browse files
committed
Simplify setting Legend attributes
1 parent deb36c9 commit 6f6ba29

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/matplotlib/legend.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,20 @@ def __init__(
385385
#: instance.
386386
self._custom_handler_map = handler_map
387387

388-
locals_view = locals()
389-
for name in ["numpoints", "markerscale", "shadow", "columnspacing",
390-
"scatterpoints", "handleheight", 'borderpad',
391-
'labelspacing', 'handlelength', 'handletextpad',
392-
'borderaxespad']:
393-
if locals_view[name] is None:
394-
value = mpl.rcParams["legend." + name]
395-
else:
396-
value = locals_view[name]
397-
setattr(self, name, value)
398-
del locals_view
388+
def val_or_rc(val, rc_name):
389+
return val if val is not None else mpl.rcParams[rc_name]
390+
391+
self.numpoints = val_or_rc(numpoints, 'legend.numpoints')
392+
self.markerscale = val_or_rc(markerscale, 'legend.markerscale')
393+
self.scatterpoints = val_or_rc(scatterpoints, 'legend.scatterpoints')
394+
self.borderpad = val_or_rc(borderpad, 'legend.borderpad')
395+
self.labelspacing = val_or_rc(labelspacing, 'legend.labelspacing')
396+
self.handlelength = val_or_rc(handlelength, 'legend.handlelength')
397+
self.handleheight = val_or_rc(handleheight, 'legend.handleheight')
398+
self.handletextpad = val_or_rc(handletextpad, 'legend.handletextpad')
399+
self.borderaxespad = val_or_rc(borderaxespad, 'legend.borderaxespad')
400+
self.columnspacing = val_or_rc(columnspacing, 'legend.columnspacing')
401+
self.shadow = val_or_rc(shadow, 'legend.shadow')
399402
# trim handles and labels if illegal label...
400403
_lab, _hand = [], []
401404
for label, handle in zip(labels, handles):

0 commit comments

Comments
 (0)