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 feea6da

Browse filesBrowse files
authored
Merge pull request #11691 from anntzer/figureframeon
Make Figure.frameon a thin wrapper for the patch visibility.
2 parents 529eb3d + a6dc4b1 commit feea6da
Copy full SHA for feea6da

File tree

Expand file treeCollapse file tree

2 files changed

+37
-28
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+37
-28
lines changed
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Figure.frameon is now a direct proxy for the Figure patch visibility state
2+
``````````````````````````````````````````````````````````````````````````
3+
4+
Accessing ``Figure.frameon`` (including via ``get_frameon`` and ``set_frameon``
5+
now directly forwards to the visibility of the underlying Rectangle artist
6+
(``Figure.patch.get_frameon``, ``Figure.patch.set_frameon``).

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+31-28Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class Figure(Artist):
254254
Attributes
255255
----------
256256
patch
257-
The `.Rectangle` instance representing the figure patch.
257+
The `.Rectangle` instance representing the figure background patch.
258258
259259
suppressComposite
260260
For multiple figure images, the figure will make composite images
@@ -304,7 +304,7 @@ def __init__(self,
304304
patch).
305305
306306
frameon : bool, default: :rc:`figure.frameon`
307-
If ``False``, suppress drawing the figure frame.
307+
If ``False``, suppress drawing the figure background patch.
308308
309309
subplotpars : :class:`SubplotParams`
310310
Subplot parameters. If not given, the default subplot
@@ -355,13 +355,12 @@ def __init__(self,
355355
self._dpi = dpi
356356
self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans)
357357

358-
self.frameon = frameon
359-
360358
self.transFigure = BboxTransformTo(self.bbox)
361359

362360
self.patch = Rectangle(
363361
xy=(0, 0), width=1, height=1,
364-
facecolor=facecolor, edgecolor=edgecolor, linewidth=linewidth)
362+
facecolor=facecolor, edgecolor=edgecolor, linewidth=linewidth,
363+
visible=frameon)
365364
self._set_artist_props(self.patch)
366365
self.patch.set_antialiased(False)
367366

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

641640
def get_children(self):
642641
"""Get a list of artists contained in the figure."""
643-
children = [self.patch]
644-
children.extend(self.artists)
645-
children.extend(self.axes)
646-
children.extend(self.lines)
647-
children.extend(self.patches)
648-
children.extend(self.texts)
649-
children.extend(self.images)
650-
children.extend(self.legends)
651-
return children
642+
return [self.patch,
643+
*self.artists,
644+
*self.axes,
645+
*self.lines,
646+
*self.patches,
647+
*self.texts,
648+
*self.images,
649+
*self.legends]
652650

653651
def contains(self, mouseevent):
654652
"""
@@ -938,8 +936,12 @@ def get_dpi(self):
938936
return self.dpi
939937

940938
def get_frameon(self):
941-
"""Return whether the figure frame will be drawn."""
942-
return self.frameon
939+
"""
940+
Return the figure's background patch visibility, i.e.
941+
whether the figure background will be drawn. Equivalent to
942+
``Figure.patch.get_visible()``.
943+
"""
944+
return self.patch.get_visible()
943945

944946
def set_edgecolor(self, color):
945947
"""
@@ -996,15 +998,19 @@ def set_figheight(self, val, forward=True):
996998

997999
def set_frameon(self, b):
9981000
"""
999-
Set whether the figure frame (background) is displayed or invisible.
1001+
Set the figure's background patch visibility, i.e.
1002+
whether the figure background will be drawn. Equivalent to
1003+
``Figure.patch.set_visible()``.
10001004
10011005
Parameters
10021006
----------
10031007
b : bool
10041008
"""
1005-
self.frameon = b
1009+
self.patch.set_visible(b)
10061010
self.stale = True
10071011

1012+
frameon = property(get_frameon, set_frameon)
1013+
10081014
def delaxes(self, ax):
10091015
"""
10101016
Remove the `~matplotlib.axes.Axes` *ax* from the figure and update the
@@ -1623,11 +1629,10 @@ def draw(self, renderer):
16231629
if not self.get_visible():
16241630
return
16251631

1632+
artists = self.get_children()
1633+
artists.remove(self.patch)
16261634
artists = sorted(
1627-
(artist for artist in (self.patches + self.lines + self.artists
1628-
+ self.images + self.axes + self.texts
1629-
+ self.legends)
1630-
if not artist.get_animated()),
1635+
(artist for artist in artists if not artist.get_animated()),
16311636
key=lambda artist: artist.get_zorder())
16321637

16331638
for ax in self.axes:
@@ -1659,9 +1664,7 @@ def draw(self, renderer):
16591664
pass
16601665
# ValueError can occur when resizing a window.
16611666

1662-
if self.frameon:
1663-
self.patch.draw(renderer)
1664-
1667+
self.patch.draw(renderer)
16651668
mimage._draw_list_compositing_images(
16661669
renderer, self, artists, self.suppressComposite)
16671670

@@ -2122,13 +2125,13 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs):
21222125
kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor'])
21232126

21242127
if frameon:
2125-
original_frameon = self.get_frameon()
2126-
self.set_frameon(frameon)
2128+
original_frameon = self.patch.get_visible()
2129+
self.patch.set_visible(frameon)
21272130

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

21302133
if frameon:
2131-
self.set_frameon(original_frameon)
2134+
self.patch.set_visible(original_frameon)
21322135

21332136
if transparent:
21342137
for ax, cc in zip(self.axes, original_axes_colors):

0 commit comments

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