diff --git a/doc/users/whats_new/rcparams.rst b/doc/users/whats_new/rcparams.rst new file mode 100644 index 000000000000..5d18925922bd --- /dev/null +++ b/doc/users/whats_new/rcparams.rst @@ -0,0 +1,6 @@ +Added "legend.framealpha" key to rcParams +``````````````````````````` + +Added a key and the corresponding logic to control the default transparency of +legend frames. This feature was written into the docstring of axes.legend(), +but not yet implemented. diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index 928f52c3b8a6..23949ce0e562 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -367,7 +367,9 @@ def __init__(self, parent, handles, labels, # init with null renderer self._init_legend_box(handles, labels) - if framealpha is not None: + if framealpha is None: + self.get_frame().set_alpha(rcParams["legend.framealpha"]) + else: self.get_frame().set_alpha(framealpha) self._loc = loc diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 7d4d97df1572..f535aec084e6 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -632,7 +632,8 @@ def __call__(self, s): 'legend.shadow': [False, validate_bool], # whether or not to draw a frame around legend 'legend.frameon': [True, validate_bool], - + # alpha value of the legend frame + 'legend.framealpha': [1.0, validate_float], ## the following dimensions are in fraction of the font size 'legend.borderpad': [0.4, validate_float], # units are fontsize diff --git a/matplotlibrc.template b/matplotlibrc.template index d3a6f3b2b28b..5669c0786b42 100644 --- a/matplotlibrc.template +++ b/matplotlibrc.template @@ -316,6 +316,7 @@ backend : %(backend)s #legend.columnspacing : 2. # the border between the axes and legend edge in fraction of fontsize #legend.shadow : False #legend.frameon : True # whether or not to draw a frame around legend +#legend.framealpha : 1.0 # opacity of of legend frame #legend.scatterpoints : 3 # number of scatter points ### FIGURE