diff --git a/doc/users/next_whats_new/2018-07-18-AL-deprecations.rst b/doc/users/next_whats_new/2018-07-18-AL-deprecations.rst new file mode 100644 index 000000000000..a8783342b10f --- /dev/null +++ b/doc/users/next_whats_new/2018-07-18-AL-deprecations.rst @@ -0,0 +1,6 @@ +Figure.frameon is now a direct proxy for the Figure patch visibility state +`````````````````````````````````````````````````````````````````````````` + +Accessing ``Figure.frameon`` (including via ``get_frameon`` and ``set_frameon`` +now directly forwards to the visibility of the underlying Rectangle artist +(``Figure.patch.get_frameon``, ``Figure.patch.set_frameon``). diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 7f13774aa111..96d479f53988 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -253,7 +253,7 @@ class Figure(Artist): Attributes ---------- patch - The `.Rectangle` instance representing the figure patch. + The `.Rectangle` instance representing the figure background patch. suppressComposite For multiple figure images, the figure will make composite images @@ -303,7 +303,7 @@ def __init__(self, patch). frameon : bool, default: :rc:`figure.frameon` - If ``False``, suppress drawing the figure frame. + If ``False``, suppress drawing the figure background patch. subplotpars : :class:`SubplotParams` Subplot parameters. If not given, the default subplot @@ -354,13 +354,12 @@ def __init__(self, self._dpi = dpi self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans) - self.frameon = frameon - self.transFigure = BboxTransformTo(self.bbox) self.patch = Rectangle( xy=(0, 0), width=1, height=1, - facecolor=facecolor, edgecolor=edgecolor, linewidth=linewidth) + facecolor=facecolor, edgecolor=edgecolor, linewidth=linewidth, + visible=frameon) self._set_artist_props(self.patch) self.patch.set_antialiased(False) @@ -640,15 +639,14 @@ def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None): def get_children(self): """Get a list of artists contained in the figure.""" - children = [self.patch] - children.extend(self.artists) - children.extend(self.axes) - children.extend(self.lines) - children.extend(self.patches) - children.extend(self.texts) - children.extend(self.images) - children.extend(self.legends) - return children + return [self.patch, + *self.artists, + *self.axes, + *self.lines, + *self.patches, + *self.texts, + *self.images, + *self.legends] def contains(self, mouseevent): """ @@ -938,8 +936,12 @@ def get_dpi(self): return self.dpi def get_frameon(self): - """Return whether the figure frame will be drawn.""" - return self.frameon + """ + Return the figure's background patch visibility, i.e. + whether the figure background will be drawn. Equivalent to + ``Figure.patch.get_visible()``. + """ + return self.patch.get_visible() def set_edgecolor(self, color): """ @@ -996,15 +998,19 @@ def set_figheight(self, val, forward=True): def set_frameon(self, b): """ - Set whether the figure frame (background) is displayed or invisible. + Set the figure's background patch visibility, i.e. + whether the figure background will be drawn. Equivalent to + ``Figure.patch.set_visible()``. Parameters ---------- b : bool """ - self.frameon = b + self.patch.set_visible(b) self.stale = True + frameon = property(get_frameon, set_frameon) + def delaxes(self, ax): """ Remove the `~matplotlib.axes.Axes` *ax* from the figure and update the @@ -1623,11 +1629,10 @@ def draw(self, renderer): if not self.get_visible(): return + artists = self.get_children() + artists.remove(self.patch) artists = sorted( - (artist for artist in (self.patches + self.lines + self.artists - + self.images + self.axes + self.texts - + self.legends) - if not artist.get_animated()), + (artist for artist in artists if not artist.get_animated()), key=lambda artist: artist.get_zorder()) try: @@ -1642,9 +1647,7 @@ def draw(self, renderer): pass # ValueError can occur when resizing a window. - if self.frameon: - self.patch.draw(renderer) - + self.patch.draw(renderer) mimage._draw_list_compositing_images( renderer, self, artists, self.suppressComposite) @@ -2104,13 +2107,13 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs): kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor']) if frameon: - original_frameon = self.get_frameon() - self.set_frameon(frameon) + original_frameon = self.patch.get_visible() + self.patch.set_visible(frameon) self.canvas.print_figure(fname, **kwargs) if frameon: - self.set_frameon(original_frameon) + self.patch.set_visible(original_frameon) if transparent: for ax, cc in zip(self.axes, original_axes_colors):