@@ -254,7 +254,7 @@ class Figure(Artist):
254
254
Attributes
255
255
----------
256
256
patch
257
- The `.Rectangle` instance representing the figure patch.
257
+ The `.Rectangle` instance representing the figure background patch.
258
258
259
259
suppressComposite
260
260
For multiple figure images, the figure will make composite images
@@ -304,7 +304,7 @@ def __init__(self,
304
304
patch).
305
305
306
306
frameon : bool, default: :rc:`figure.frameon`
307
- If ``False``, suppress drawing the figure frame .
307
+ If ``False``, suppress drawing the figure background patch .
308
308
309
309
subplotpars : :class:`SubplotParams`
310
310
Subplot parameters. If not given, the default subplot
@@ -355,13 +355,12 @@ def __init__(self,
355
355
self ._dpi = dpi
356
356
self .bbox = TransformedBbox (self .bbox_inches , self .dpi_scale_trans )
357
357
358
- self .frameon = frameon
359
-
360
358
self .transFigure = BboxTransformTo (self .bbox )
361
359
362
360
self .patch = Rectangle (
363
361
xy = (0 , 0 ), width = 1 , height = 1 ,
364
- facecolor = facecolor , edgecolor = edgecolor , linewidth = linewidth )
362
+ facecolor = facecolor , edgecolor = edgecolor , linewidth = linewidth ,
363
+ visible = frameon )
365
364
self ._set_artist_props (self .patch )
366
365
self .patch .set_antialiased (False )
367
366
@@ -640,15 +639,14 @@ def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None):
640
639
641
640
def get_children (self ):
642
641
"""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 ]
652
650
653
651
def contains (self , mouseevent ):
654
652
"""
@@ -938,8 +936,12 @@ def get_dpi(self):
938
936
return self .dpi
939
937
940
938
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 ()
943
945
944
946
def set_edgecolor (self , color ):
945
947
"""
@@ -996,15 +998,19 @@ def set_figheight(self, val, forward=True):
996
998
997
999
def set_frameon (self , b ):
998
1000
"""
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()``.
1000
1004
1001
1005
Parameters
1002
1006
----------
1003
1007
b : bool
1004
1008
"""
1005
- self .frameon = b
1009
+ self .patch . set_visible ( b )
1006
1010
self .stale = True
1007
1011
1012
+ frameon = property (get_frameon , set_frameon )
1013
+
1008
1014
def delaxes (self , ax ):
1009
1015
"""
1010
1016
Remove the `~matplotlib.axes.Axes` *ax* from the figure and update the
@@ -1623,11 +1629,10 @@ def draw(self, renderer):
1623
1629
if not self .get_visible ():
1624
1630
return
1625
1631
1632
+ artists = self .get_children ()
1633
+ artists .remove (self .patch )
1626
1634
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 ()),
1631
1636
key = lambda artist : artist .get_zorder ())
1632
1637
1633
1638
for ax in self .axes :
@@ -1659,9 +1664,7 @@ def draw(self, renderer):
1659
1664
pass
1660
1665
# ValueError can occur when resizing a window.
1661
1666
1662
- if self .frameon :
1663
- self .patch .draw (renderer )
1664
-
1667
+ self .patch .draw (renderer )
1665
1668
mimage ._draw_list_compositing_images (
1666
1669
renderer , self , artists , self .suppressComposite )
1667
1670
@@ -2122,13 +2125,13 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs):
2122
2125
kwargs .setdefault ('edgecolor' , rcParams ['savefig.edgecolor' ])
2123
2126
2124
2127
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 )
2127
2130
2128
2131
self .canvas .print_figure (fname , ** kwargs )
2129
2132
2130
2133
if frameon :
2131
- self .set_frameon (original_frameon )
2134
+ self .patch . set_visible (original_frameon )
2132
2135
2133
2136
if transparent :
2134
2137
for ax , cc in zip (self .axes , original_axes_colors ):
0 commit comments