8000 Legend shadow color by Tranquilled · Pull Request #18668 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Legend shadow color #18668

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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
5 changes: 1 addition & 4 deletions doc/api/animation_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ on all systems.

FFMpegWriter
ImageMagickWriter
AVConvWriter

The file-based writers save temporary files for each frame which are stitched
into a single file at the end. Although slower, these writers can be easier to
Expand All @@ -198,7 +197,6 @@ debug.

FFMpegFileWriter
ImageMagickFileWriter
AVConvFileWriter

Fundamentally, a `MovieWriter` provides a way to grab sequential frames
from the same underlying `~matplotlib.figure.Figure` object. The base
Expand Down Expand Up @@ -283,7 +281,6 @@ and mixins
:toctree: _as_gen
:nosignatures:

AVConvBase
FFMpegBase
ImageMagickBase

Expand All @@ -298,6 +295,6 @@ Inheritance Diagrams
:private-bases:
:parts: 1

.. inheritance-diagram:: matplotlib.animation.AVConvFileWriter matplotlib.animation.AVConvWriter matplotlib.animation.FFMpegFileWriter matplotlib.animation.FFMpegWriter matplotlib.animation.ImageMagickFileWriter matplotlib.animation.ImageMagickWriter
.. inheritance-diagram:: matplotlib.animation.FFMpegFileWriter matplotlib.animation.FFMpegWriter matplotlib.animation.ImageMagickFileWriter matplotlib.animation.ImageMagickWriter
:private-bases:
:parts: 1
50 changes: 0 additions & 50 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,17 +584,6 @@ def output_args(self):

return args + ['-y', self.outfile]

@classmethod
def isAvailable(cls):
return (
super().isAvailable()
# Ubuntu 12.04 ships a broken ffmpeg binary which we shouldn't use.
# NOTE: when removed, remove the same method in AVConvBase.
and b'LibAv' not in subprocess.run(
[cls.bin_path()], creationflags=subprocess_creation_flags,
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE).stderr)


# Combine FFMpeg options with pipe-based writing
@writers.register('ffmpeg')
Expand Down Expand Up @@ -640,45 +629,6 @@ def _args(self):
'-vframes', str(self._frame_counter)] + self.output_args


# Base class of avconv information. AVConv has identical arguments to FFMpeg.
@cbook.deprecated('3.3')
class AVConvBase(FFMpegBase):
"""
Mixin class for avconv output.

To be useful this must be multiply-inherited from with a
`MovieWriterBase` sub-class.
"""

_exec_key = 'animation.avconv_path'
_args_key = 'animation.avconv_args'

# NOTE : should be removed when the same method is removed in FFMpegBase.
isAvailable = classmethod(MovieWriter.isAvailable.__func__)


# Combine AVConv options with pipe-based writing
@writers.register('avconv')
class AVConvWriter(AVConvBase, FFMpegWriter):
"""
Pipe-based avconv writer.

Frames are streamed directly to avconv via a pipe and written in a single
pass.
"""


# Combine AVConv options with file-based writing
@writers.register('avconv_file')
class AVConvFileWriter(AVConvBase, FFMpegFileWriter):
"""
File-based avconv writer.

Frames are written to temporary files on disk and then stitched
together at the end.
"""


# Base class for animated GIFs with ImageMagick
class ImageMagickBase:
"""
Expand Down
15 changes: 13 additions & 2 deletions lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
shadow : bool, default: :rc:`legend.shadow`
Whether to draw a shadow behind the legend.

shadowcolor : color or None
Takes a valid color string. If ``None``, defaults to the legend's
``facecolor`` as usual.
Sets shadow color directly if shadow is activated.

framealpha : float, default: :rc:`legend.framealpha`
The alpha transparency of the legend's background.
If *shadow* is activated and *framealpha* is ``None``, the default value is
Expand Down Expand Up @@ -322,6 +327,7 @@ def __init__(self, parent, handles, labels,
fancybox=None, # True use a fancy box, false use a rounded
# box, none use rc
shadow=None,
shadowcolor=None, # set shadow color directly
title=None, # set a title for the legend
title_fontsize=None, # the font size for the title
framealpha=None, # set frame alpha
Expand Down Expand Up @@ -514,7 +520,6 @@ def __init__(self, parent, handles, labels,
self._draggable = None

# set the text color

color_getters = { # getter function depends on line or patch
'linecolor': ['get_color', 'get_facecolor'],
'markerfacecolor': ['get_markerfacecolor', 'get_facecolor'],
Expand Down Expand Up @@ -543,6 +548,9 @@ def __init__(self, parent, handles, labels,
raise ValueError("Invalid argument for labelcolor : %s" %
str(labelcolor))

# set shadow color
self.shadowcolor = shadowcolor

def _set_artist_props(self, a):
"""
Set the boilerplate props for artists added to axes.
Expand Down Expand Up @@ -607,7 +615,10 @@ def draw(self, renderer):
self.legendPatch.set_bounds(bbox.x0, bbox.y0, bbox.width, bbox.height)
self.legendPatch.set_mutation_scale(fontsize)

if self.shadow:
if self.shadowcolor and self.shadow:
Shadow(self.legendPatch, 2, -2,
color=self.shadowcolor).draw(renderer)
elif self.shadow:
Shadow(self.legendPatch, 2, -2).draw(renderer)

self.legendPatch.draw(renderer)
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ legend.handletextpad : 0.8 # the space between the legend line and legend tex
legend.borderaxespad : 0.5 # the border between the axes and legend edge in fraction of fontsize
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.shadowcolor : None # sets shadow color; defaults to legend.facecolor
legend.frameon : True # whether or not to draw a frame around legend
legend.framealpha : None # opacity of legend frame
legend.scatterpoints : 3 # number of scatter points
legend.facecolor : inherit # legend background color (when 'inherit' uses axes.facecolor)
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,7 @@ def _convert_validator_spec(key, conv):
# the relative size of legend markers vs. original
"legend.markerscale": validate_float,
"legend.shadow": validate_bool,
"legend.shadowcolor": validate_color,
# whether or not to draw a frame around legend
"legend.frameon": validate_bool,
# alpha value of the legend frame
Expand Down
1 change: 1 addition & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@
#legend.fancybox: True # if True, use a rounded box for the
# legend background, else a rectangle
#legend.shadow: False # if True, give background a shadow effect
#legend.shadowcolor: None # takes a color string, otherwise default behavior
#legend.numpoints: 1 # the number of marker points in the legend line
#legend.scatterpoints: 1 # number of scatter points
#legend.markerscale: 1.0 # the relative size of legend markers vs. original
Expand Down
0