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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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``).
45 changes: 21 additions & 24 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
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 @@ -939,7 +937,7 @@ def get_dpi(self):

def get_frameon(self):
"""Return whether the figure frame will be drawn."""
return self.frameon
return self.patch.get_visible()

def set_edgecolor(self, color):
"""
Expand Down Expand Up @@ -1002,9 +1000,11 @@ def set_frameon(self, b):
----------
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 +1623,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 +1641,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 +2101,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