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

Skip to content

Make Figure.frameon a thin wrapper for the patch visibility. #11691

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 3 commits into from
Dec 28, 2018
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
6 changes: 6 additions & 0 deletions doc/users/next_whats_new/2018-07-18-AL-deprecations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Figure.frameon is now a direct proxy for the Figure patch visibility state
``````````````````````````````````````````````````````````````````````````

Accessing ``Figure.frameon`` (including via ``get_frameon`` and ``set_frameon``
now directly forwards to the visibility of the underlying Rectangle artist
(``Figure.patch.get_frameon``, ``Figure.patch.set_frameon``).
59 changes: 31 additions & 28 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class Figure(Artist):
Attributes
----------
patch
The `.Rectangle` instance representing the figure patch.
The `.Rectangle` instance representing the figure background patch.

suppressComposite
For multiple figure images, the figure will make composite images
Expand Down Expand Up @@ -303,7 +303,7 @@ def __init__(self,
patch).

frameon : bool, default: :rc:`figure.frameon`
If ``False``, suppress drawing the figure frame.
If ``False``, suppress drawing the figure background patch.

subplotpars : :class:`SubplotParams`
Subplot parameters. If not given, the default subplot
Expand Down Expand Up @@ -354,13 +354,12 @@ def __init__(self,
self._dpi = dpi
self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans)

self.frameon = frameon

self.transFigure = BboxTransformTo(self.bbox)

self.patch = Rectangle(
xy=(0, 0), width=1, height=1,
facecolor=facecolor, edgecolor=edgecolor, linewidth=linewidth)
facecolor=facecolor, edgecolor=edgecolor, linewidth=linewidth,
visible=frameon)
self._set_artist_props(self.patch)
self.patch.set_antialiased(False)

Expand Down Expand Up @@ -640,15 +639,14 @@ def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None):

def get_children(self):
"""Get a list of artists contained in the figure."""
children = [self.patch]
children.extend(self.artists)
children.extend(self.axes)
children.extend(self.lines)
children.extend(self.patches)
children.extend(self.texts)
children.extend(self.images)
children.extend(self.legends)
return children
return [self.patch,
*self.artists,
*self.axes,
*self.lines,
*self.patches,
*self.texts,
*self.images,
*self.legends]

def contains(self, mouseevent):
"""
Expand Down Expand Up @@ -938,8 +936,12 @@ def get_dpi(self):
return self.dpi

def get_frameon(self):
"""Return whether the figure frame will be drawn."""
return self.frameon
"""
Return the figure's background patch visibility, i.e.
whether the figure background will be drawn. Equivalent to
``Figure.patch.get_visible()``.
"""
return self.patch.get_visible()

def set_edgecolor(self, color):
"""
Expand Down Expand Up @@ -996,15 +998,19 @@ def set_figheight(self, val, forward=True):

def set_frameon(self, b):
"""
Set whether the figure frame (background) is displayed or invisible.
Set the figure's background patch visibility, i.e.
whether the figure background will be drawn. Equivalent to
``Figure.patch.set_visible()``.

Parameters
----------
b : bool
"""
self.frameon = b
self.patch.set_visible(b)
self.stale = True

frameon = property(get_frameon, set_frameon)

def delaxes(self, ax):
"""
Remove the `~matplotlib.axes.Axes` *ax* from the figure and update the
Expand Down Expand Up @@ -1623,11 +1629,10 @@ def draw(self, renderer):
if not self.get_visible():
return

artists = self.get_children()
artists.remove(self.patch)
artists = sorted(
(artist for artist in (self.patches + self.lines + self.artists
+ self.images + self.axes + self.texts
+ self.legends)
if not artist.get_animated()),
(artist for artist in artists if not artist.get_animated()),
key=lambda artist: artist.get_zorder())

try:
Expand All @@ -1642,9 +1647,7 @@ def draw(self, renderer):
pass
# ValueError can occur when resizing a window.

if self.frameon:
self.patch.draw(renderer)

self.patch.draw(renderer)
mimage._draw_list_compositing_images(
renderer, self, artists, self.suppressComposite)

Expand Down Expand Up @@ -2104,13 +2107,13 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs):
kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor'])

if frameon:
original_frameon = self.get_frameon()
self.set_frameon(frameon)
original_frameon = self.patch.get_visible()
self.patch.set_visible(frameon)

self.canvas.print_figure(fname, **kwargs)

if frameon:
self.set_frameon(original_frameon)
self.patch.set_visible(original_frameon)

if transparent:
for ax, cc in zip(self.axes, original_axes_colors):
Expand Down