Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f6a929c

Browse filesBrowse files
committed
Remove shadowcolor flag; allow color values for shadow flag
1 parent ea20273 commit f6a929c
Copy full SHA for f6a929c

File tree

Expand file treeCollapse file tree

5 files changed

+47
-19
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+47
-19
lines changed

‎lib/matplotlib/legend.py

Copy file name to clipboardExpand all lines: lib/matplotlib/legend.py
+11-15Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from matplotlib import _api, cbook, docstring, colors
3232
from matplotlib.artist import Artist, allow_rasterization
3333
from matplotlib.cbook import silent_list
34+
from matplotlib.colors import is_color_like
3435
from matplotlib.font_manager import FontProperties
3536
from matplotlib.lines import Line2D
3637
from matplotlib.patches import (Patch, Rectangle, Shadow, FancyBboxPatch,
@@ -208,13 +209,11 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
208209
Whether round edges should be enabled around the `~.FancyBboxPatch` which
209210
makes up the legend's background.
210211
211-
shadow : bool, default: :rc:`legend.shadow`
212+
shadow : bool or color, default: :rc:`legend.shadow`
212213
Whether to draw a shadow behind the legend.
213-
214-
shadowcolor : color or None
215-
Takes a valid color string. If ``None``, defaults to the legend's
216-
``facecolor`` as usual.
217-
Sets shadow color directly if shadow is activated.
214+
If value is a color, a shadow of that color will be applied.
215+
If the value is neither boolean nor a valid color, behavior is that of
216+
*True* and the shadow is the default color.
218217
219218
framealpha : float, default: :rc:`legend.framealpha`
220219
The alpha transparency of the legend's background.
@@ -327,7 +326,6 @@ def __init__(self, parent, handles, labels,
327326
fancybox=None, # True use a fancy box, false use a rounded
328327
# box, none use rc
329328
shadow=None,
330-
shadowcolor=None, # set shadow color directly
331329
title=None, # set a title for the legend
332330
title_fontsize=None, # the font size for the title
333331
framealpha=None, # set frame alpha
@@ -548,9 +546,6 @@ def __init__(self, parent, handles, labels,
548546
raise ValueError("Invalid argument for labelcolor : %s" %
549547
str(labelcolor))
550548

551-
# set shadow color
552-
self.shadowcolor = shadowcolor
553-
554549
def _set_artist_props(self, a):
555550
"""
556551
Set the boilerplate props for artists added to axes.
@@ -615,11 +610,12 @@ def draw(self, renderer):
615610
self.legendPatch.set_bounds(bbox.x0, bbox.y0, bbox.width, bbox.height)
616611
self.legendPatch.set_mutation_scale(fontsize)
617612

618-
if self.shadowcolor and self.shadow:
619-
Shadow(self.legendPatch, 2, -2,
620-
color=self.shadowcolor).draw(renderer)
621-
elif self.shadow:
622-
Shadow(self.legendPatch, 2, -2).draw(renderer)
613+
if self.shadow:
614+
shadow = self.shadow
615+
if is_color_like(shadow):
616+
Shadow(self.legendPatch, 2, -2, color=shadow).draw(renderer)
617+
else:
618+
Shadow(self.legendPatch, 2, -2).draw(renderer)
623619

624620
self.legendPatch.draw(renderer)
625621
self._legend_box.draw(renderer)

‎lib/matplotlib/mpl-data/stylelib/classic.mplstyle

Copy file name to clipboardExpand all lines: lib/matplotlib/mpl-data/stylelib/classic.mplstyle
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ legend.handletextpad : 0.8 # the space between the legend line and legend tex
294294
legend.borderaxespad : 0.5 # the border between the axes and legend edge in fraction of fontsize
295295
legend.columnspacing : 2. # the border between the axes and legend edge in fraction of fontsize
296296
legend.shadow : False
297-
legend.shadowcolor : None # sets shadow color; defaults to legend.facecolor
298297
legend.frameon : True # whether or not to draw a frame around legend
299298
legend.framealpha : None # opacity of legend frame
300299
legend.scatterpoints : 3 # number of scatter points

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ def validate_bool(b):
147147
raise ValueError('Could not convert "%s" to bool' % b)
148148

149149

150+
def validate_color_or_bool(c):
151+
"""Convert c to color (preferentially) or bool"""
152+
try:
153+
return validate_color(c)
154+
except ValueError:
155+
return validate_bool(c)
156+
157+
150158
@cbook.deprecated("3.3")
151159
def validate_bool_maybe_none(b):
152160
"""Convert b to ``bool`` or raise, passing through *None*."""
@@ -1245,8 +1253,7 @@ def _convert_validator_spec(key, conv):
12451253
"legend.title_fontsize": validate_fontsize_None,
12461254
# the relative size of legend markers vs. original
12471255
"legend.markerscale": validate_float,
1248-
"legend.shadow": validate_bool,
1249-
"legend.shadowcolor": validate_color,
1256+
"legend.shadow": validate_color_or_bool,
12501257
# whether or not to draw a frame around legend
12511258
"legend.frameon": validate_bool,
12521259
# alpha value of the legend frame

‎lib/matplotlib/tests/test_rcparams.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_rcparams.py
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
validate_bool_maybe_none,
2020
validate_color,
2121
validate_colorlist,
22+
validate_color_or_bool,
2223
validate_cycler,
2324
validate_float,
2425
validate_fontweight,
@@ -340,6 +341,32 @@ def generate_validator_testcases(valid):
340341
('(0, 1, "0.5")', ValueError), # last one not a float
341342
),
342343
},
344+
{'validator': validate_color_or_bool,
345+
'success': (('None', 'none'),
346+
('none', 'none'),
347+
('AABBCC', '#AABBCC'), # RGB hex code
348+
('AABBCC00', '#AABBCC00'), # RGBA hex code
349+
('tab:blue', 'tab:blue'), # named color
350+
('C12', 'C12'), # color from cycle
351+
('(0, 1, 0)', (0.0, 1.0, 0.0)), # RGB tuple
352+
((0, 1, 0), (0, 1, 0)), # non-string version
353+
('(0, 1, 0, 1)', (0.0, 1.0, 0.0, 1.0)), # RGBA tuple
354+
((0, 1, 0, 1), (0, 1, 0, 1)), # non-string version
355+
*((_, True) for _ in
356+
('t', 'yes', 'on', 'true', 1, True)),
357+
*((_, False) for _ in
358+
('f', 'n', 'no', 'off', 'false', 0, False)),
359+
),
360+
'fail': (('tab:veryblue', ValueError), # invalid name
361+
('(0, 1)', ValueError), # tuple with length < 3
362+
('(0, 1, 0, 1, 0)', ValueError), # tuple with length > 4
363+
('(0, 1, none)', ValueError), # cannot cast none to float
364+
('(0, 1, "0.5")', ValueError), # last one not a float
365+
(2, ValueError),
366+
(-1, ValueError),
367+
([], ValueError),
368+
),
369+
},
343370
{'validator': validate_hist_bins,
344371
'success': (('auto', 'auto'),
345372
('fd', 'fd'),

‎matplotlibrc.template

Copy file name to clipboardExpand all lines: matplotlibrc.template
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@
520520
#legend.fancybox: True # if True, use a rounded box for the
521521
# legend background, else a rectangle
522522
#legend.shadow: False # if True, give background a shadow effect
523-
#legend.shadowcolor: None # takes a color string, otherwise default behavior
524523
#legend.numpoints: 1 # the number of marker points in the legend line
525524
#legend.scatterpoints: 1 # number of scatter points
526525
#legend.markerscale: 1.0 # the relative size of legend markers vs. original

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.