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

Skip to content

BUG : correct default value alpha on legend patch #3773

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
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ def validate_float(s):
raise ValueError('Could not convert "%s" to float' % s)


def validate_float_or_None(s):
"""convert s to float or raise"""
if s is None:
return None
try:
return float(s)
except ValueError:
raise ValueError('Could not convert "%s" to float' % s)


def validate_int(s):
"""convert s to int or raise"""
try:
Expand Down Expand Up @@ -640,7 +650,7 @@ def __call__(self, s):
# 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],
'legend.framealpha': [None, validate_float_or_None],

## the following dimensions are in fraction of the font size
'legend.borderpad': [0.4, validate_float], # units are fontsize
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ def test_various_labels():
ax.legend(numpoints=1, loc=0)


@image_comparison(baseline_images=['rgba_alpha'],
extensions=['png'], remove_text=True)
def test_alpha_rgba():
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 1)
ax.plot(range(10), lw=5)
leg = plt.legend(['Longlabel that will go away'], loc=10)
leg.legendPatch.set_facecolor([1, 0, 0, 0.5])


@image_comparison(baseline_images=['rcparam_alpha'],
extensions=['png'], remove_text=True)
def test_alpha_rcparam():
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 1)
ax.plot(range(10), lw=5)
with mpl.rc_context(rc={'legend.framealpha': .75}):
leg = plt.legend(['Longlabel that will go away'], loc=10)
# this alpha is going to be over-ridden by the rcparam whith
# sets the alpha of the patch to be non-None which causes the alpha
# value of the face color to be discarded. This behavior may not be
# ideal, but it is what it is and we should keep track of it changing
leg.legendPatch.set_facecolor([1, 0, 0, 0.5])


@image_comparison(baseline_images=['fancy'], remove_text=True)
def test_fancy():
# using subplot triggers some offsetbox functionality untested elsewhere
Expand Down
14 changes: 7 additions & 7 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ backend : %(backend)s
# separator in the fr_FR locale.
#axes.formatter.use_mathtext : False # When True, use mathtext for scientific
# notation.
#axes.formatter.useoffset : True # If True, the tick label formatter
# will default to labeling ticks relative
# to an offset when the data range is very
# small compared to the minimum absolute
#axes.formatter.useoffset : True # If True, the tick label formatter
# will default to labeling ticks relative
# to an offset when the data range is very
# small compared to the minimum absolute
# value of the data.

#axes.unicode_minus : True # use unicode for the minus symbol
Expand Down Expand Up @@ -320,7 +320,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.framealpha : None # opacity of of legend frame
#legend.scatterpoints : 3 # number of scatter points

### FIGURE
Expand Down Expand Up @@ -399,7 +399,7 @@ backend : %(backend)s
#savefig.jpeg_quality: 95 # when a jpeg is saved, the default quality parameter.
#savefig.directory : ~ # default directory in savefig dialog box,
# leave empty to always use current working directory
#savefig.transparent : False # setting that controls whether figures are saved with a
#savefig.transparent : False # setting that controls whether figures are saved with a
# transparent background by default

# tk backend params
Expand Down Expand Up @@ -489,5 +489,5 @@ backend : %(backend)s
# $PATH is searched
#animation.mencoder_args: '' # Additional arguments to pass to mencoder
#animation.convert_path: 'convert' # Path to ImageMagick's convert binary.
# On Windows use the full path since convert
# On Windows use the full path since convert
# is also the name of a system tool.