@@ -354,13 +354,12 @@ def __init__(self,
354
354
self ._dpi = dpi
355
355
self .bbox = TransformedBbox (self .bbox_inches , self .dpi_scale_trans )
356
356
357
- self .frameon = frameon
358
-
359
357
self .transFigure = BboxTransformTo (self .bbox )
360
358
361
359
self .patch = Rectangle (
362
360
xy = (0 , 0 ), width = 1 , height = 1 ,
363
- facecolor = facecolor , edgecolor = edgecolor , linewidth = linewidth )
361
+ facecolor = facecolor , edgecolor = edgecolor , linewidth = linewidth ,
362
+ visible = frameon )
364
363
self ._set_artist_props (self .patch )
365
364
self .patch .set_antialiased (False )
366
365
@@ -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
"""
@@ -937,9 +935,10 @@ def get_dpi(self):
937
935
"""Return the resolution in dots per inch as a float."""
938
936
return self .dpi
939
937
938
+ @cbook .deprecated ("3.1" , alternative = "figure.patch.get_visible" )
940
939
def get_frameon (self ):
941
940
"""Return whether the figure frame will be drawn."""
942
- return self .frameon
941
+ return self .patch . get_visible ()
943
942
944
943
def set_edgecolor (self , color ):
945
944
"""
@@ -994,6 +993,7 @@ def set_figheight(self, val, forward=True):
994
993
"""
995
994
self .set_size_inches (self .get_figwidth (), val , forward = forward )
996
995
996
+ @cbook .deprecated ("3.1" , alternative = "figure.patch.set_visible" )
997
997
def set_frameon (self , b ):
998
998
"""
999
999
Set whether the figure frame (background) is displayed or invisible.
@@ -1002,9 +1002,11 @@ def set_frameon(self, b):
1002
1002
----------
1003
1003
b : bool
1004
1004
"""
1005
- self .frameon = b
1005
+ self .patch . set_visible ( b )
1006
1006
self .stale = True
1007
1007
1008
+ frameon = property (get_frameon , set_frameon )
1009
+
1008
1010
def delaxes (self , ax ):
1009
1011
"""
1010
1012
Remove the `~matplotlib.axes.Axes` *ax* from the figure and update the
@@ -1623,11 +1625,10 @@ def draw(self, renderer):
1623
1625
if not self .get_visible ():
1624
1626
return
1625
1627
1628
+ artists = self .get_children ()
1629
+ artists .remove (self .patch )
1626
1630
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 ()),
1631
1632
key = lambda artist : artist .get_zorder ())
1632
1633
1633
1634
try :
@@ -1642,9 +1643,7 @@ def draw(self, renderer):
1642
1643
pass
1643
1644
# ValueError can occur when resizing a window.
1644
1645
1645
- if self .frameon :
1646
- self .patch .draw (renderer )
1647
-
1646
+ self .patch .draw (renderer )
1648
1647
mimage ._draw_list_compositing_images (
1649
1648
renderer , self , artists , self .suppressComposite )
1650
1649
@@ -2104,13 +2103,13 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs):
2104
2103
kwargs .setdefault ('edgecolor' , rcParams ['savefig.edgecolor' ])
2105
2104
2106
2105
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 )
2109
2108
2110
2109
self .canvas .print_figure (fname , ** kwargs )
2111
2110
2112
2111
if frameon :
2113
- self .set_frameon (original_frameon )
2112
+ self .patch . set_visible (original_frameon )
2114
2113
2115
2114
if transparent :
2116
2115
for ax , cc in zip (self .axes , original_axes_colors ):
0 commit comments