@@ -360,13 +360,12 @@ def __init__(self,
360
360
self ._dpi = dpi
361
361
self .bbox = TransformedBbox (self .bbox_inches , self .dpi_scale_trans )
362
362
363
- self .frameon = frameon
364
-
365
363
self .transFigure = BboxTransformTo (self .bbox )
366
364
367
365
self .patch = Rectangle (
368
366
xy = (0 , 0 ), width = 1 , height = 1 ,
369
- facecolor = facecolor , edgecolor = edgecolor , linewidth = linewidth )
367
+ facecolor = facecolor , edgecolor = edgecolor , linewidth = linewidth ,
368
+ visible = frameon )
370
369
self ._set_artist_props (self .patch )
371
370
self .patch .set_aa (False )
372
371
@@ -649,15 +648,14 @@ def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None):
649
648
650
649
def get_children (self ):
651
650
"""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 ]
661
659
662
660
def contains (self , mouseevent ):
663
661
"""
@@ -946,9 +944,10 @@ def get_dpi(self):
946
944
"""Return the resolution in dots per inch as a float."""
947
945
return self .dpi
948
946
947
+ @cbook .deprecated ("3.1" , alternative = "figure.patch.get_visible" )
949
948
def get_frameon (self ):
950
949
"""Return whether the figure frame will be drawn."""
951
- return self .frameon
950
+ return self .patch . get_visible ()
952
951
953
952
def set_edgecolor (self , color ):
954
953
"""
@@ -997,6 +996,7 @@ def set_figheight(self, val, forward=True):
997
996
"""
998
997
self .set_size_inches (self .get_figwidth (), val , forward = forward )
999
998
999
+ @cbook .deprecated ("3.1" , alternative = "figure.patch.set_visible" )
1000
1000
def set_frameon (self , b ):
1001
1001
"""
1002
1002
Set whether the figure frame (background) is displayed or invisible.
@@ -1005,9 +1005,11 @@ def set_frameon(self, b):
1005
1005
----------
1006
1006
b : bool
1007
1007
"""
1008
- self .frameon = b
1008
+ self .patch . set_visible ( b )
1009
1009
self .stale = True
1010
1010
1011
+ frameon = property (get_frameon , set_frameon )
1012
+
1011
1013
def delaxes (self , ax ):
1012
1014
"""
1013
1015
Remove the `~matplotlib.axes.Axes` *ax* from the figure and update the
@@ -1590,11 +1592,10 @@ def draw(self, renderer):
1590
1592
if not self .get_visible ():
1591
1593
return
1592
1594
1595
+ artists = self .get_children ()
1596
+ artists .remove (self .patch )
1593
1597
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 ()),
1598
1599
key = lambda artist : artist .get_zorder ())
1599
1600
1600
1601
try :
@@ -1609,9 +1610,7 @@ def draw(self, renderer):
1609
1610
pass
1610
1611
# ValueError can occur when resizing a window.
1611
1612
1612
- if self .frameon :
1613
- self .patch .draw (renderer )
1614
-
1613
+ self .patch .draw (renderer )
1615
1614
mimage ._draw_list_compositing_images (
1616
1615
renderer , self , artists , self .suppressComposite )
1617
1616
@@ -2045,13 +2044,13 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs):
2045
2044
kwargs .setdefault ('edgecolor' , rcParams ['savefig.edgecolor' ])
2046
2045
2047
2046
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 )
2050
2049
2051
2050
self .canvas .print_figure (fname , ** kwargs )
2052
2051
2053
2052
if frameon :
2054
- self .set_frameon (original_frameon )
2053
+ self .patch . set_visible (original_frameon )
2055
2054
2056
2055
if transparent :
2057
2056
for ax , cc in zip (self .axes , original_axes_colors ):
0 commit comments