Skip to content

Group all init of Legend.legendPatch together. #16351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 16 additions & 30 deletions lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,45 +483,31 @@ def __init__(self, parent, handles, labels,
if edgecolor == 'inherit':
edgecolor = mpl.rcParams["axes.edgecolor"]

self.legendPatch = FancyBboxPatch(
xy=(0.0, 0.0), width=1., height=1.,
facecolor=facecolor,
edgecolor=edgecolor,
mutation_scale=self._fontsize,
snap=True
)

# The width and height of the legendPatch will be set (in the
# draw()) to the length that includes the padding. Thus we set
# pad=0 here.
if fancybox is None:
fancybox = mpl.rcParams["legend.fancybox"]

if fancybox:
self.legendPatch.set_boxstyle("round", pad=0,
rounding_size=0.2)
else:
self.legendPatch.set_boxstyle("square", pad=0)

self.legendPatch = FancyBboxPatch(
xy=(0, 0), width=1, height=1,
facecolor=facecolor, edgecolor=edgecolor,
# If shadow is used, default to alpha=1 (#8943).
alpha=(framealpha if framealpha is not None
else 1 if shadow
else mpl.rcParams["legend.framealpha"]),
# The width and height of the legendPatch will be set (in draw())
# to the length that includes the padding. Thus we set pad=0 here.
boxstyle=("round,pad=0,rounding_size=0.2" if fancybox
else "square,pad=0"),
mutation_scale=self._fontsize,
snap=True,
)
self._set_artist_props(self.legendPatch)

self._drawFrame = frameon
if frameon is None:
self._drawFrame = mpl.rcParams["legend.frameon"]
self._drawFrame = (frameon if frameon is not None
else mpl.rcParams["legend.frameon"])

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

# If shadow is activated use framealpha if not
# explicitly passed. See Issue 8943
if framealpha is None:
if shadow:
self.get_frame().set_alpha(1)
else:
self.get_frame().set_alpha(mpl.rcParams["legend.framealpha"])
else:
self.get_frame().set_alpha(framealpha)

tmp = self._loc_used_default
self._set_loc(loc)
self._loc_used_default = tmp # ignore changes done by _set_loc
Expand Down