8000 Deprecate Figure.frameon. · matplotlib/matplotlib@4ed83c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ed83c1

Browse files
committed
Deprecate Figure.frameon.
Directly manipulating the visibility of Figure.patch is just as good.
1 parent 8d66b47 commit 4ed83c1

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Deprecations
2+
````````````
3+
4+
The following API elements are deprecated:
5+
6+
- ``Figure.frameon``, ``Figure.get_frameon``, ``Figure.set_frameon`` (directly
7+
manipulate the visibility of ``Figure.patch`` instead),

lib/matplotlib/figure.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -643,15 +642,14 @@ def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None):
643642

644643
def get_children(self):
645644
"""Get a list of artists contained in the figure."""
646-
children = [self.patch]
647-
children.extend(self.artists)
648-
children.extend(self.axes)
649-
children.extend(self.lines)
650-
children.extend(self.patches)
651-
children.extend(self.texts)
652-
children.extend(self.images)
653-
children.extend(self.legends)
654-
return children
645+
return [self.patch,
646+
*self.artists,
647+
*self.axes,
648+
*self.lines,
649+
*self.patches,
650+
*self.texts,
651+
*self.images,
652+
*self.legends]
655653

656654
def contains(self, mouseevent):
657655
"""
@@ -940,9 +938,10 @@ def get_dpi(self):
940938
"""Return the resolution in dots per inch as a float."""
941939
return self.dpi
942940

941+
@cbook.deprecated("3.1", alternative="figure.patch.get_visible")
943942
def get_frameon(self):
944943
"""Return whether the figure frame will be drawn."""
945-
return self.frameon
944+
return self.patch.get_visible()
946945

947946
def set_edgecolor(self, color):
948947
"""
@@ -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
@@ -1626,11 +1628,10 @@ def draw(self, renderer):
16261628
if not self.get_visible():
16271629
return
16281630

1631+
artists = self.get_children()
1632+
artists.remove(self.patch)
16291633
artists = sorted(
1630-
(artist for artist in (self.patches + self.lines + self.artists
1631-
+ self.images + self.axes + self.texts
1632-
+ self.legends)
1633-
if not artist.get_animated()),
1634+
(artist for artist in artists if not artist.get_animated()),
16341635
key=lambda artist: artist.get_zorder())
16351636

16361637
try:
@@ -1645,9 +1646,7 @@ def draw(self, renderer):
16451646
pass
16461647
# ValueError can occur when resizing a window.
16471648

1648-
if self.frameon:
1649-
self.patch.draw(renderer)
1650-
1649+
self.patch.draw(renderer)
16511650
mimage._draw_list_compositing_images(
16521651
renderer, self, artists, self.suppressComposite)
16531652

@@ -2107,13 +2106,13 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs):
21072106
kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor'])
21082107

21092108
if frameon:
2110-
original_frameon = self.get_frameon()
2111-
self.set_frameon(frameon)
2109+
original_frameon = self.patch.get_visible()
2110+
self.patch.set_visible(frameon)
21122111

21132112
self.canvas.print_figure(fname, **kwargs)
21142113

21152114
if frameon:
2116-
self.set_frameon(original_frameon)
2115+
self.patch.set_visible(original_frameon)
21172116

21182117
if transparent:
21192118
for ax, cc in zip(self.axes, original_axes_colors):

0 commit comments

Comments
 (0)
0