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

Skip to content

Commit 11c0bcc

Browse files
committed
Merge pull request #3773 from tacaswell/fix_legend.framalpha_default
BUG : correct default value alpha on legend patch
2 parents 924d06b + d0f5d85 commit 11c0bcc

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ def validate_float(s):
108108
raise ValueError('Could not convert "%s" to float' % s)
109109

110110

111+
def validate_float_or_None(s):
112+
"""convert s to float or raise"""
113+
if s is None:
114+
return None
115+
try:
116+
return float(s)
117+
except ValueError:
118+
raise ValueError('Could not convert "%s" to float' % s)
119+
120+
111121
def validate_int(s):
112122
"""convert s to int or raise"""
113123
try:
@@ -640,7 +650,7 @@ def __call__(self, s):
640650
# whether or not to draw a frame around legend
641651
'legend.frameon': [True, validate_bool],
642652
# alpha value of the legend frame
643-
'legend.framealpha': [1.0, validate_float],
653+
'legend.framealpha': [None, validate_float_or_None],
644654

645655
## the following dimensions are in fraction of the font size
646656
'legend.borderpad': [0.4, validate_float], # units are fontsize

lib/matplotlib/tests/test_legend.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,33 @@ def test_various_labels():
6464
ax.legend(numpoints=1, loc=0)
6565

6666

67+
@image_comparison(baseline_images=['rgba_alpha'],
68+
extensions=['png'], remove_text=True)
69+
def test_alpha_rgba():
70+
import matplotlib.pyplot as plt
71+
72+
fig, ax = plt.subplots(1, 1)
73+
ax.plot(range(10), lw=5)
74+
leg = plt.legend(['Longlabel that will go away'], loc=10)
75+
leg.legendPatch.set_facecolor([1, 0, 0, 0.5])
76+
77+
78+
@image_comparison(baseline_images=['rcparam_alpha'],
79+
extensions=['png'], remove_text=True)
80+
def test_alpha_rcparam():
81+
import matplotlib.pyplot as plt
82+
83+
fig, ax = plt.subplots(1, 1)
84+
ax.plot(range(10), lw=5)
85+
with mpl.rc_context(rc={'legend.framealpha': .75}):
86+
leg = plt.legend(['Longlabel that will go away'], loc=10)
87+
# this alpha is going to be over-ridden by the rcparam whith
88+
# sets the alpha of the patch to be non-None which causes the alpha
89+
# value of the face color to be discarded. This behavior may not be
90+
# ideal, but it is what it is and we should keep track of it changing
91+
leg.legendPatch.set_facecolor([1, 0, 0, 0.5])
92+
93+
6794
@image_comparison(baseline_images=['fancy'], remove_text=True)
6895
def test_fancy():
6996
# using subplot triggers some offsetbox functionality untested elsewhere

matplotlibrc.template

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ backend : %(backend)s
255255
# separator in the fr_FR locale.
256256
#axes.formatter.use_mathtext : False # When True, use mathtext for scientific
257257
# notation.
258-
#axes.formatter.useoffset : True # If True, the tick label formatter
259-
# will default to labeling ticks relative
260-
# to an offset when the data range is very
261-
# small compared to the minimum absolute
258+
#axes.formatter.useoffset : True # If True, the tick label formatter
259+
# will default to labeling ticks relative
260+
# to an offset when the data range is very
261+
# small compared to the minimum absolute
262262
# value of the data.
263263

264264
#axes.unicode_minus : True # use unicode for the minus symbol
@@ -320,7 +320,7 @@ backend : %(backend)s
320320
#legend.columnspacing : 2. # the border between the axes and legend edge in fraction of fontsize
321321
#legend.shadow : False
322322
#legend.frameon : True # whether or not to draw a frame around legend
323-
#legend.framealpha : 1.0 # opacity of of legend frame
323+
#legend.framealpha : None # opacity of of legend frame
324324
#legend.scatterpoints : 3 # number of scatter points
325325

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

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

0 commit comments

Comments
 (0)