@@ -354,13 +354,12 @@ def __init__(self,
354354 self ._dpi = dpi
355355 self .bbox = TransformedBbox (self .bbox_inches , self .dpi_scale_trans )
356356
357- self .frameon = frameon
358-
359357 self .transFigure = BboxTransformTo (self .bbox )
360358
361359 self .patch = Rectangle (
362360 xy = (0 , 0 ), width = 1 , height = 1 ,
363- facecolor = facecolor , edgecolor = edgecolor , linewidth = linewidth )
361+ facecolor = facecolor , edgecolor = edgecolor , linewidth = linewidth ,
362+ visible = frameon )
364363 self ._set_artist_props (self .patch )
365364 self .patch .set_antialiased (False )
366365
@@ -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 """
@@ -937,9 +935,10 @@ def get_dpi(self):
937935 """Return the resolution in dots per inch as a float."""
938936 return self .dpi
939937
938+ @cbook .deprecated ("3.1" , alternative = "figure.patch.get_visible" )
940939 def get_frameon (self ):
941940 """Return whether the figure frame will be drawn."""
942- return self .frameon
941+ return self .patch . get_visible ()
943942
944943 def set_edgecolor (self , color ):
945944 """
@@ -994,6 +993,7 @@ def set_figheight(self, val, forward=True):
994993 """
995994 self .set_size_inches (self .get_figwidth (), val , forward = forward )
996995
996+ @cbook .deprecated ("3.1" , alternative = "figure.patch.set_visible" )
997997 def set_frameon (self , b ):
998998 """
999999 Set whether the figure frame (background) is displayed or invisible.
@@ -1002,9 +1002,11 @@ def set_frameon(self, b):
10021002 ----------
10031003 b : bool
10041004 """
1005- self .frameon = b
1005+ self .patch . set_visible ( b )
10061006 self .stale = True
10071007
1008+ frameon = property (get_frameon , set_frameon )
1009+
10081010 def delaxes (self , ax ):
10091011 """
10101012 Remove the `~matplotlib.axes.Axes` *ax* from the figure and update the
@@ -1623,11 +1625,10 @@ def draw(self, renderer):
16231625 if not self .get_visible ():
16241626 return
16251627
1628+ artists = self .get_children ()
1629+ artists .remove (self .patch )
16261630 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 ()),
1631+ (artist for artist in artists if not artist .get_animated ()),
16311632 key = lambda artist : artist .get_zorder ())
16321633
16331634 try :
@@ -1642,9 +1643,7 @@ def draw(self, renderer):
16421643 pass
16431644 # ValueError can occur when resizing a window.
16441645
1645- if self .frameon :
1646- self .patch .draw (renderer )
1647-
1646+ self .patch .draw (renderer )
16481647 mimage ._draw_list_compositing_images (
16491648 renderer , self , artists , self .suppressComposite )
16501649
@@ -2104,13 +2103,13 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs):
21042103 kwargs .setdefault ('edgecolor' , rcParams ['savefig.edgecolor' ])
21052104
21062105 if frameon :
2107- original_frameon = self .get_frameon ()
2108- self .set_frameon (frameon )
2106+ original_frameon = self .patch . get_visible ()
2107+ self .patch . set_visible (frameon )
21092108
21102109 self .canvas .print_figure (fname , ** kwargs )
21112110
21122111 if frameon :
2113- self .set_frameon (original_frameon )
2112+ self .patch . set_visible (original_frameon )
21142113
21152114 if transparent :
21162115 for ax , cc in zip (self .axes , original_axes_colors ):
0 commit comments