@@ -360,13 +360,12 @@ def __init__(self,
360360 self ._dpi = dpi
361361 self .bbox = TransformedBbox (self .bbox_inches , self .dpi_scale_trans )
362362
363- self .frameon = frameon
364-
365363 self .transFigure = BboxTransformTo (self .bbox )
366364
367365 self .patch = Rectangle (
368366 xy = (0 , 0 ), width = 1 , height = 1 ,
369- facecolor = facecolor , edgecolor = edgecolor , linewidth = linewidth )
367+ facecolor = facecolor , edgecolor = edgecolor , linewidth = linewidth ,
368+ visible = frameon )
370369 self ._set_artist_props (self .patch )
371370 self .patch .set_aa (False )
372371
@@ -649,15 +648,14 @@ def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None):
649648
650649 def get_children (self ):
651650 """Get a list of artists contained in the figure."""
652- children = [self .patch ]
653- children .extend (self .artists )
654- children .extend (self .axes )
655- children .extend (self .lines )
656- children .extend (self .patches )
657- children .extend (self .texts )
658- children .extend (self .images )
659- children .extend (self .legends )
660- return children
651+ return [self .patch ,
652+ * self .artists ,
653+ * self .axes ,
654+ * self .lines ,
655+ * self .patches ,
656+ * self .texts ,
657+ * self .images ,
658+ * self .legends ]
661659
662660 def contains (self , mouseevent ):
663661 """
@@ -946,9 +944,10 @@ def get_dpi(self):
946944 """Return the resolution in dots per inch as a float."""
947945 return self .dpi
948946
947+ @cbook .deprecated ("3.1" , alternative = "figure.patch.get_visible" )
949948 def get_frameon (self ):
950949 """Return whether the figure frame will be drawn."""
951- return self .frameon
950+ return self .patch . get_visible ()
952951
953952 def set_edgecolor (self , color ):
954953 """
@@ -997,6 +996,7 @@ def set_figheight(self, val, forward=True):
997996 """
998997 self .set_size_inches (self .get_figwidth (), val , forward = forward )
999998
999+ @cbook .deprecated ("3.1" , alternative = "figure.patch.set_visible" )
10001000 def set_frameon (self , b ):
10011001 """
10021002 Set whether the figure frame (background) is displayed or invisible.
@@ -1005,9 +1005,11 @@ def set_frameon(self, b):
10051005 ----------
10061006 b : bool
10071007 """
1008- self .frameon = b
1008+ self .patch . set_visible ( b )
10091009 self .stale = True
10101010
1011+ frameon = property (get_frameon , set_frameon )
1012+
10111013 def delaxes (self , ax ):
10121014 """
10131015 Remove the `~matplotlib.axes.Axes` *ax* from the figure and update the
@@ -1590,11 +1592,10 @@ def draw(self, renderer):
15901592 if not self .get_visible ():
15911593 return
15921594
1595+ artists = self .get_children ()
1596+ artists .remove (self .patch )
15931597 artists = sorted (
1594- (artist for artist in (self .patches + self .lines + self .artists
1595- + self .images + self .axes + self .texts
1596- + self .legends )
1597- if not artist .get_animated ()),
1598+ (artist for artist in artists if not artist .get_animated ()),
15981599 key = lambda artist : artist .get_zorder ())
15991600
16001601 try :
@@ -1609,9 +1610,7 @@ def draw(self, renderer):
16091610 pass
16101611 # ValueError can occur when resizing a window.
16111612
1612- if self .frameon :
1613- self .patch .draw (renderer )
1614-
1613+ self .patch .draw (renderer )
16151614 mimage ._draw_list_compositing_images (
16161615 renderer , self , artists , self .suppressComposite )
16171616
@@ -2045,13 +2044,13 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs):
20452044 kwargs .setdefault ('edgecolor' , rcParams ['savefig.edgecolor' ])
20462045
20472046 if frameon :
2048- original_frameon = self .get_frameon ()
2049- self .set_frameon (frameon )
2047+ original_frameon = self .patch . get_visible ()
2048+ self .patch . set_visible (frameon )
20502049
20512050 self .canvas .print_figure (fname , ** kwargs )
20522051
20532052 if frameon :
2054- self .set_frameon (original_frameon )
2053+ self .patch . set_visible (original_frameon )
20552054
20562055 if transparent :
20572056 for ax , cc in zip (self .axes , original_axes_colors ):
0 commit comments