From c69ec43431264fdfe1dd9765114627ff6461e573 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 18 Jul 2018 14:51:09 +0200 Subject: [PATCH 1/3] Deprecate Figure.frameon. Directly manipulating the visibility of Figure.patch is just as good. --- .../2018-07-18-AL-deprecations.rst | 7 +++ lib/matplotlib/figure.py | 47 +++++++++---------- 2 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 doc/users/next_whats_new/2018-07-18-AL-deprecations.rst 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..0e50360bb951 --- /dev/null +++ b/doc/users/next_whats_new/2018-07-18-AL-deprecations.rst @@ -0,0 +1,7 @@ +Deprecations +```````````` + +The following API elements are deprecated: + +- ``Figure.frameon``, ``Figure.get_frameon``, ``Figure.set_frameon`` (directly + manipulate the visibility of ``Figure.patch`` instead), diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 7f13774aa111..281f6c468181 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -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): """ @@ -937,9 +935,10 @@ def get_dpi(self): """Return the resolution in dots per inch as a float.""" return self.dpi + @cbook.deprecated("3.1", alternative="figure.patch.get_visible") def get_frameon(self): """Return whether the figure frame will be drawn.""" - return self.frameon + return self.patch.get_visible() def set_edgecolor(self, color): """ @@ -994,6 +993,7 @@ def set_figheight(self, val, forward=True): """ self.set_size_inches(self.get_figwidth(), val, forward=forward) + @cbook.deprecated("3.1", alternative="figure.patch.set_visible") def set_frameon(self, b): """ Set whether the figure frame (background) is displayed or invisible. @@ -1002,9 +1002,11 @@ def set_frameon(self, b): ---------- 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 +1625,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 +1643,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 +2103,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): From 5b2cfd9bad9e9b0f7db705d8f45eaf723d4c5338 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 10 Oct 2018 16:39:41 +0200 Subject: [PATCH 2/3] Undeprecate frameon. --- .../next_whats_new/2018-07-18-AL-deprecations.rst | 11 +++++------ lib/matplotlib/figure.py | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-) 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 index 0e50360bb951..a8783342b10f 100644 --- a/doc/users/next_whats_new/2018-07-18-AL-deprecations.rst +++ b/doc/users/next_whats_new/2018-07-18-AL-deprecations.rst @@ -1,7 +1,6 @@ -Deprecations -```````````` +Figure.frameon is now a direct proxy for the Figure patch visibility state +`````````````````````````````````````````````````````````````````````````` -The following API elements are deprecated: - -- ``Figure.frameon``, ``Figure.get_frameon``, ``Figure.set_frameon`` (directly - manipulate the visibility of ``Figure.patch`` instead), +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 281f6c468181..d5191b66db5f 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -935,7 +935,6 @@ def get_dpi(self): """Return the resolution in dots per inch as a float.""" return self.dpi - @cbook.deprecated("3.1", alternative="figure.patch.get_visible") def get_frameon(self): """Return whether the figure frame will be drawn.""" return self.patch.get_visible() @@ -993,7 +992,6 @@ def set_figheight(self, val, forward=True): """ self.set_size_inches(self.get_figwidth(), val, forward=forward) - @cbook.deprecated("3.1", alternative="figure.patch.set_visible") def set_frameon(self, b): """ Set whether the figure frame (background) is displayed or invisible. From a6dc4b18caca6b5131c89e725c9a8a149057b121 Mon Sep 17 00:00:00 2001 From: ImportanceOfBeingErnest Date: Sun, 14 Oct 2018 03:46:01 +0200 Subject: [PATCH 3/3] frameon-doc-update --- lib/matplotlib/figure.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index d5191b66db5f..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 @@ -936,7 +936,11 @@ def get_dpi(self): return self.dpi def get_frameon(self): - """Return whether the figure frame will be drawn.""" + """ + 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): @@ -994,7 +998,9 @@ 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 ----------