Skip to content

Commit ffe6c78

Browse files
authored
Merge pull request #16351 from anntzer/shortlegend
Group all init of Legend.legendPatch together.
2 parents 90fb532 + e6c3c5d commit ffe6c78

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

lib/matplotlib/legend.py

+16-30
Original file line numberDiff line numberDiff line change
@@ -483,45 +483,31 @@ def __init__(self, parent, handles, labels,
483483
if edgecolor == 'inherit':
484484
edgecolor = mpl.rcParams["axes.edgecolor"]
485485

486-
self.legendPatch = FancyBboxPatch(
487-
xy=(0.0, 0.0), width=1., height=1.,
488-
facecolor=facecolor,
489-
edgecolor=edgecolor,
490-
mutation_scale=self._fontsize,
491-
snap=True
492-
)
493-
494-
# The width and height of the legendPatch will be set (in the
495-
# draw()) to the length that includes the padding. Thus we set
496-
# pad=0 here.
497486
if fancybox is None:
498487
fancybox = mpl.rcParams["legend.fancybox"]
499488

500-
if fancybox:
501-
self.legendPatch.set_boxstyle("round", pad=0,
502-
rounding_size=0.2)
503-
else:
504-
self.legendPatch.set_boxstyle("square", pad=0)
505-
489+
self.legendPatch = FancyBboxPatch(
490+
xy=(0, 0), width=1, height=1,
491+
facecolor=facecolor, edgecolor=edgecolor,
492+
# If shadow is used, default to alpha=1 (#8943).
493+
alpha=(framealpha if framealpha is not None
494+
else 1 if shadow
495+
else mpl.rcParams["legend.framealpha"]),
496+
# The width and height of the legendPatch will be set (in draw())
497+
# to the length that includes the padding. Thus we set pad=0 here.
498+
boxstyle=("round,pad=0,rounding_size=0.2" if fancybox
499+
else "square,pad=0"),
500+
mutation_scale=self._fontsize,
501+
snap=True,
502+
)
506503
self._set_artist_props(self.legendPatch)
507504

508-
self._drawFrame = frameon
509-
if frameon is None:
510-
self._drawFrame = mpl.rcParams["legend.frameon"]
505+
self._drawFrame = (frameon if frameon is not None
506+
else mpl.rcParams["legend.frameon"])
511507

512508
# init with null renderer
513509
self._init_legend_box(handles, labels, markerfirst)
514510

515-
# If shadow is activated use framealpha if not
516-
# explicitly passed. See Issue 8943
517-
if framealpha is None:
518-
if shadow:
519-
self.get_frame().set_alpha(1)
520-
else:
521-
self.get_frame().set_alpha(mpl.rcParams["legend.framealpha"])
522-
else:
523-
self.get_frame().set_alpha(framealpha)
524-
525511
tmp = self._loc_used_default
526512
self._set_loc(loc)
527513
self._loc_used_default = tmp # ignore changes done by _set_loc

0 commit comments

Comments
 (0)