From fbbbc514fb5b30fb4cc5236b6abfaf423f6e8fbd Mon Sep 17 00:00:00 2001 From: Marin Gilles Date: Sun, 26 Jul 2015 15:55:49 +0200 Subject: [PATCH 1/5] added deprecation warning function --- lib/matplotlib/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index ead63f4f3af6..4b50d93085db 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1501,6 +1501,20 @@ def test(verbosity=1): if old_backend.lower() != 'agg': use(old_backend) +def deprecated_get_set(function, to_use): + """Fuction to deprecate the getters and setter for a class + argument. + + Parameter + --------- + - function: function + The function to deprecate. + - to_use: string + The argument to use instead of the deprecated function + """ + msg = "{} is deprecated, please use the {} argument" + msg = msg.format(function.__name__, to_use) + warnings.warn(msg, mplDeprecation, stacklevel=1) return success test.__test__ = False # nose: this function is not a test From 1a5307489e4abf700f501b1962c0279666d05fac Mon Sep 17 00:00:00 2001 From: Marin Gilles Date: Fri, 31 Jul 2015 23:31:42 +0200 Subject: [PATCH 2/5] Added figure as a property and deprecated setters and getters --- lib/matplotlib/__init__.py | 4 +-- lib/matplotlib/artist.py | 25 ++++++++++++++----- lib/matplotlib/axes/_base.py | 19 +++++++++----- lib/matplotlib/axes/_subplots.py | 13 +++++++++- lib/matplotlib/axis.py | 8 +++--- .../backends/qt_editor/figureoptions.py | 2 +- lib/matplotlib/colorbar.py | 6 ++--- lib/matplotlib/figure.py | 6 ++--- lib/matplotlib/image.py | 4 +-- lib/matplotlib/legend.py | 8 +++--- lib/matplotlib/legend_handler.py | 4 +-- lib/matplotlib/offsetbox.py | 18 +++++++++---- lib/matplotlib/patches.py | 2 +- lib/matplotlib/quiver.py | 10 +++++--- lib/matplotlib/spines.py | 2 +- lib/matplotlib/table.py | 12 ++++++--- lib/matplotlib/tests/test_text.py | 8 +++--- lib/matplotlib/text.py | 20 ++++++++++----- lib/mpl_toolkits/axes_grid/colorbar.py | 2 +- lib/mpl_toolkits/axes_grid1/axes_divider.py | 4 +-- lib/mpl_toolkits/axes_grid1/axes_rgb.py | 14 +++++------ lib/mpl_toolkits/axes_grid1/axes_size.py | 6 ++--- lib/mpl_toolkits/axes_grid1/colorbar.py | 2 +- lib/mpl_toolkits/axisartist/axis_artist.py | 2 +- lib/mpl_toolkits/axisartist/floating_axes.py | 2 +- 25 files changed, 129 insertions(+), 74 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 4b50d93085db..2e522a07ce9a 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1500,6 +1500,7 @@ def test(verbosity=1): finally: if old_backend.lower() != 'agg': use(old_backend) + return success def deprecated_get_set(function, to_use): """Fuction to deprecate the getters and setter for a class @@ -1512,10 +1513,9 @@ def deprecated_get_set(function, to_use): - to_use: string The argument to use instead of the deprecated function """ - msg = "{} is deprecated, please use the {} argument" + msg = "{} is deprecated, please use the `{}` argument" msg = msg.format(function.__name__, to_use) warnings.warn(msg, mplDeprecation, stacklevel=1) - return success test.__test__ = False # nose: this function is not a test diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index e6d428fba997..be0c4ff1494e 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -9,7 +9,7 @@ import matplotlib import matplotlib.cbook as cbook from matplotlib.cbook import mplDeprecation -from matplotlib import docstring, rcParams +from matplotlib import docstring, rcParams, deprecated_get_set from .transforms import (Bbox, IdentityTransform, TransformedBbox, TransformedPath, Transform) from .path import Path @@ -88,7 +88,7 @@ class Artist(object): def __init__(self): self._stale = True self._axes = None - self.figure = None + self._figure = None self._transform = None self._transformSet = False @@ -594,11 +594,27 @@ def set_path_effects(self, path_effects): def get_path_effects(self): return self._path_effects + @property + def figure(self): + """:class:`~matplotlib.figure.Figure` instance the artist + belongs to""" + return self._figure + + @figure.setter + def figure(self, fig): + self._figure = fig + if self._figure and self._figure is not self: + self.add_callback(_stale_figure_callback) + self.pchanged() + self.stale = True + + def get_figure(self): """ Return the :class:`~matplotlib.figure.Figure` instance the artist belongs to. """ + deprecated_get_set(self.get_figure, "figure") return self.figure def set_figure(self, fig): @@ -608,11 +624,8 @@ def set_figure(self, fig): ACCEPTS: a :class:`matplotlib.figure.Figure` instance """ + deprecated_get_set(self.set_figure, "figure") self.figure = fig - if self.figure and self.figure is not self: - self.add_callback(_stale_figure_callback) - self.pchanged() - self.stale = True def set_clip_box(self, clipbox): """ diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 0b3f8b20a738..20b2943eb5f3 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -421,7 +421,7 @@ def __init__(self, fig, rect, # 'shared axes: "adjustable" is being changed to "datalim"') self._adjustable = 'datalim' self.set_label(label) - self.set_figure(fig) + self.figure = fig self.set_axes_locator(kwargs.get("axes_locator", None)) @@ -500,8 +500,16 @@ def set_figure(self, fig): accepts a class:`~matplotlib.figure.Figure` instance """ - martist.Artist.set_figure(self, fig) + # import ipdb; ipdb.set_trace() + self.figure = fig + @martist.Artist.figure.getter + def figure(self): + return self._figure + + @martist.Artist.figure.setter + def figure(self, fig): + martist.Artist.figure.__set__(self, fig) self.bbox = mtransforms.TransformedBbox(self._position, fig.transFigure) # these will be updated later as data is added @@ -509,7 +517,6 @@ def set_figure(self, fig): self.viewLim = mtransforms.Bbox.unit() self.transScale = mtransforms.TransformWrapper( mtransforms.IdentityTransform()) - self._set_lim_and_transforms() def _set_lim_and_transforms(self): @@ -781,7 +788,7 @@ def get_axes_locator(self): def _set_artist_props(self, a): """set the boilerplate props for artists added to axes""" - a.set_figure(self.figure) + a.figure = self.figure if not a.is_transform_set(): a.set_transform(self.transData) @@ -959,7 +966,7 @@ def cla(self): # deprecated. We use the frame to draw the edges so we are # setting the edgecolor to None self.patch = self.axesPatch = self._gen_axes_patch() - self.patch.set_figure(self.figure) + self.patch.figure = self.figure self.patch.set_facecolor(self._axisbg) self.patch.set_edgecolor('None') self.patch.set_linewidth(0) @@ -1211,7 +1218,7 @@ def apply_aspect(self, position=None): warnings.warn( 'shared axes: "adjustable" is being changed to "datalim"') - figW, figH = self.get_figure().get_size_inches() + figW, figH = self.figure.get_size_inches() fig_aspect = figH / figW if self._adjustable in ['box', 'box-forced']: if aspect_scale_mode == "log": diff --git a/lib/matplotlib/axes/_subplots.py b/lib/matplotlib/axes/_subplots.py index 118a557b5bf6..83cc09fb198f 100644 --- a/lib/matplotlib/axes/_subplots.py +++ b/lib/matplotlib/axes/_subplots.py @@ -35,7 +35,9 @@ def __init__(self, fig, *args, **kwargs): decimal integer *numRows* * 100 + *numCols* * 10 + *plotNum*. """ - self.figure = fig + self._figure = fig + # self._figure = None + # self.figure = fig if len(args) == 1: if isinstance(args[0], SubplotSpec): @@ -86,6 +88,15 @@ def not_subplotbase(c): self.__getstate__()] return tuple(r) + # @property + # def figure(self): + # """:class:`~matplotlib.figure.Figure` the subplot is set to""" + # return self._figure + + # @figure.setter + # def figure(self, fig): + # self._figure = fig + def get_geometry(self): """get the subplot geometry, e.g., 2,2,3""" rows, cols, num1, num2 = self.get_subplotspec().get_geometry() diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 0710eddf1154..38adb1a3346b 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -97,7 +97,7 @@ def __init__(self, axes, loc, label, else: gridOn = False - self.set_figure(axes.figure) + self.figure = axes.figure self.axes = axes name = self.__name__.lower() @@ -277,7 +277,7 @@ def set_label2(self, s): self.stale = True def _set_artist_props(self, a): - a.set_figure(self.figure) + a.figure = self.figure def get_view_interval(self): 'return the view Interval instance for the axis this tick is ticking' @@ -625,7 +625,7 @@ def __init__(self, axes, pickradius=15): Init the axis with the parent Axes instance """ artist.Artist.__init__(self) - self.set_figure(axes.figure) + self.figure = axes.figure # Keep track of setting to the default value, this allows use to know # if any of the following values is explicitly set by the user, so as @@ -883,7 +883,7 @@ def set_default_intervals(self): def _set_artist_props(self, a): if a is None: return - a.set_figure(self.figure) + a.figure = self.figure def iter_ticks(self): """ diff --git a/lib/matplotlib/backends/qt_editor/figureoptions.py b/lib/matplotlib/backends/qt_editor/figureoptions.py index bf1ec010c176..5ac17cab3517 100644 --- a/lib/matplotlib/backends/qt_editor/figureoptions.py +++ b/lib/matplotlib/backends/qt_editor/figureoptions.py @@ -154,7 +154,7 @@ def apply_callback(data): new_legend.draggable(draggable) # Redraw - figure = axes.get_figure() + figure = axes.figure figure.canvas.draw() data = formlayout.fedit(datalist, title="Figure options", parent=parent, diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 82d5a04f7341..723bf0fcbb13 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -1095,8 +1095,8 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15, if not isinstance(parents, (list, tuple)): parents = [parents] - fig = parents[0].get_figure() - if not all(fig is ax.get_figure() for ax in parents): + fig = parents[0].figure + if not all(fig is ax.figure for ax in parents): raise ValueError('Unable to create a colorbar axes as not all ' 'parents share the same figure.') @@ -1232,7 +1232,7 @@ def make_axes_gridspec(parent, **kw): parent.set_position(parent.figbox) parent.set_anchor(panchor) - fig = parent.get_figure() + fig = parent.figure cax = fig.add_subplot(gs2[1]) cax.set_aspect(aspect, anchor=anchor, adjustable='box') return cax, kw diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 073d6889f74a..05f2ef33d6e7 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -888,7 +888,7 @@ def add_axes(self, *args, **kwargs): if isinstance(args[0], Axes): a = args[0] - if a.get_figure() is not self: + if a.figure is not self: msg = "The Axes must have been created in the present figure" raise ValueError(msg) else: @@ -965,7 +965,7 @@ def add_subplot(self, *args, **kwargs): if isinstance(args[0], SubplotBase): a = args[0] - if a.get_figure() is not self: + if a.figure is not self: msg = ("The Subplot must have been created in the present" " figure") raise ValueError(msg) @@ -1271,7 +1271,7 @@ def text(self, x, y, s, *args, **kwargs): def _set_artist_props(self, a): if a != self: - a.set_figure(self) + a.figure = self a.set_transform(self.transFigure) @docstring.dedent_interpd diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 01e36e831785..210505ecea13 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -1127,7 +1127,7 @@ def __init__(self, bbox, def get_window_extent(self, renderer=None): if renderer is None: - renderer = self.get_figure()._cachedRenderer + renderer = self.figure._cachedRenderer if isinstance(self.bbox, BboxBase): return self.bbox @@ -1141,7 +1141,7 @@ def contains(self, mouseevent): if six.callable(self._contains): return self._contains(self, mouseevent) - if not self.get_visible(): # or self.get_figure()._renderer is None: + if not self.get_visible(): # or self.figure._renderer is None: return False, {} x, y = mouseevent.x, mouseevent.y diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index 4f18d0526e6f..8d641a2818a5 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -304,10 +304,10 @@ def __init__(self, parent, handles, labels, if isinstance(parent, Axes): self.isaxes = True self.axes = parent - self.set_figure(parent.figure) + self.figure = parent.figure elif isinstance(parent, Figure): self.isaxes = False - self.set_figure(parent) + self.figure = parent else: raise TypeError("Legend needs either Axes or Figure as parent") self.parent = parent @@ -398,7 +398,7 @@ def _set_artist_props(self, a): """ set the boilerplate props for artists added to axes """ - a.set_figure(self.figure) + a.figure = self.figure if self.isaxes: # a.set_axes(self.axes) a.axes = self.axes @@ -714,7 +714,7 @@ def _init_legend_box(self, handles, labels, markerfirst=True): align="center", children=[self._legend_title_box, self._legend_handle_box]) - self._legend_box.set_figure(self.figure) + self._legend_box.figure = self.figure self.texts = text_list self.legendHandles = handle_list diff --git a/lib/matplotlib/legend_handler.py b/lib/matplotlib/legend_handler.py index 82fbea1f88cd..3ab29b470761 100644 --- a/lib/matplotlib/legend_handler.py +++ b/lib/matplotlib/legend_handler.py @@ -327,7 +327,7 @@ def update_prop(self, legend_handle, orig_handle, legend): self._update_prop(legend_handle, orig_handle) - legend_handle.set_figure(legend.figure) + legend_handle.figure = legend.figure #legend._set_artist_props(legend_handle) legend_handle.set_clip_box(None) legend_handle.set_clip_path(None) @@ -610,7 +610,7 @@ def get_first(prop_array): legend_handle.set_linewidth(get_first(orig_handle.get_linewidths())) legend_handle.set_linestyle(get_first(orig_handle.get_linestyles())) legend_handle.set_transform(get_first(orig_handle.get_transforms())) - legend_handle.set_figure(orig_handle.get_figure()) + legend_handle.figure = orig_handle.figure legend_handle.set_alpha(orig_handle.get_alpha()) def create_artists(self, legend, orig_handle, diff --git a/lib/matplotlib/offsetbox.py b/lib/matplotlib/offsetbox.py index 932babbde485..bf847896351d 100644 --- a/lib/matplotlib/offsetbox.py +++ b/lib/matplotlib/offsetbox.py @@ -183,9 +183,13 @@ def set_figure(self, fig): accepts a class:`~matplotlib.figure.Figure` instance """ - martist.Artist.set_figure(self, fig) + self.figure = fig + + @martist.Artist.figure.setter + def figure(self, fig): + martist.Artist.figure.__set__(self, fig) for c in self.get_children(): - c.set_figure(fig) + c.figure = fig def contains(self, mouseevent): for c in self.get_children(): @@ -1460,11 +1464,15 @@ def get_children(self): return children def set_figure(self, fig): + self.figure = fig + @martist.Artist.figure.setter + def figure(self, fig): if self.arrow_patch is not None: - self.arrow_patch.set_figure(fig) - self.offsetbox.set_figure(fig) - martist.Artist.set_figure(self, fig) + self.arrow_patch.figure = fig + self.offsetbox.figure = fig + martist.Artist.figure.__set__(self, fig) + def set_fontsize(self, s=None): """ diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 6a120f0badd3..73256ad5c4b8 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -177,7 +177,7 @@ def update_from(self, other): self.set_linewidth(other.get_linewidth()) self.set_linestyle(other.get_linestyle()) self.set_transform(other.get_data_transform()) - self.set_figure(other.get_figure()) + self.figure = other.figure self.set_alpha(other.get_alpha()) def get_extents(self): diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index f2c7aab2d187..255faa5748a2 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -309,7 +309,7 @@ def _init(self): if self.color is not None: self.vector.set_color(self.color) self.vector.set_transform(self.Q.get_transform()) - self.vector.set_figure(self.get_figure()) + self.vector.figure = self.figure self._initialized = True def _text_x(self, x): @@ -351,8 +351,12 @@ def _set_transform(self): raise ValueError('unrecognized coordinates') def set_figure(self, fig): - martist.Artist.set_figure(self, fig) - self.text.set_figure(fig) + self.figure = fig + + @martist.Artist.figure.setter + def figure(self, fig): + martist.Artist.figure.__set__(self, fig) + self.text.figure = fig def contains(self, mouseevent): # Maybe the dictionary should allow one to diff --git a/lib/matplotlib/spines.py b/lib/matplotlib/spines.py index a68245086c31..248e499cf6fe 100644 --- a/lib/matplotlib/spines.py +++ b/lib/matplotlib/spines.py @@ -53,7 +53,7 @@ def __init__(self, axes, spine_type, path, **kwargs): """ super(Spine, self).__init__(**kwargs) self.axes = axes - self.set_figure(self.axes.figure) + self.figure = self.axes.figure self.spine_type = spine_type self.set_facecolor('none') self.set_edgecolor(rcParams['axes.edgecolor']) diff --git a/lib/matplotlib/table.py b/lib/matplotlib/table.py index 2d8adfbd5db3..98e782699216 100644 --- a/lib/matplotlib/table.py +++ b/lib/matplotlib/table.py @@ -71,8 +71,12 @@ def set_transform(self, trans): self.stale = True def set_figure(self, fig): - Rectangle.set_figure(self, fig) - self._text.set_figure(fig) + self.figure = fig + + @Rectangle.figure.setter + def figure(self, fig): + Rectangle.figure.__set__(self, fig) + self._text.figure = fig def get_text(self): 'Return the cell Text intance' @@ -260,7 +264,7 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs): loc = 'bottom' if is_string_like(loc): loc = self.codes.get(loc, 1) - self.set_figure(ax.figure) + self.figure = ax.figure self._axes = ax self._loc = loc self._bbox = bbox @@ -285,7 +289,7 @@ def add_cell(self, row, col, *args, **kwargs): xy = (0, 0) cell = CustomCell(xy, visible_edges=self.edges, *args, **kwargs) - cell.set_figure(self.figure) + cell.figure = self.figure cell.set_transform(self.get_transform()) cell.set_clip_on(False) diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index 6403fb018bf1..21dda68e0083 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -337,10 +337,10 @@ def test_text_annotation_get_window_extent(): # Only text annotation annotation = Annotation('test', xy=(0, 0)) - annotation.set_figure(figure) + annotation.figure = figure text = Text(text='test', x=0, y=0) - text.set_figure(figure) + text.figure = figure bbox = annotation.get_window_extent(renderer=renderer) @@ -410,7 +410,7 @@ def test_arrow_annotation_get_window_extent(): '', xy=(0.0, 50.0), xytext=(50.0, 50.0), xycoords='figure pixels', arrowprops={ 'facecolor': 'black', 'width': 8, 'headwidth': 10, 'shrink': 0.0}) - annotation.set_figure(figure) + annotation.figure = figure annotation.draw(renderer) bbox = annotation.get_window_extent() @@ -432,7 +432,7 @@ def test_empty_annotation_get_window_extent(): # Text annotation with arrow annotation = Annotation( '', xy=(0.0, 50.0), xytext=(0.0, 50.0), xycoords='figure pixels') - annotation.set_figure(figure) + annotation.figure = figure annotation.draw(renderer) bbox = annotation.get_window_extent() diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 4ee58f3f3e88..25d794c43161 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -628,7 +628,7 @@ def _get_wrap_line_width(self): current orientation. """ x0, y0 = self.get_transform().transform(self.get_position()) - figure_box = self.get_figure().get_window_extent() + figure_box = self.figure.get_window_extent() # Calculate available width based on text alignment alignment = self.get_horizontalalignment() @@ -1624,8 +1624,12 @@ def set_figure(self, fig): ACCEPTS: a :class:`matplotlib.figure.Figure` instance """ - Text.set_figure(self, fig) - self.dashline.set_figure(fig) + self.figure = fig + + @Text.figure.setter + def figure(self, fig): + Text.figure.__set__(self, fig) + docstring.interpd.update(TextWithDash=artist.kwdoc(TextWithDash)) @@ -2023,6 +2027,7 @@ def __init__(self, s, xy, xy, xycoords=xycoords, annotation_clip=annotation_clip) + # warn about wonky input data if (xytext is None and textcoords is not None and @@ -2081,12 +2086,15 @@ def anncoords(self, coords): self._textcoords = coords def set_figure(self, fig): + self.figure = fig + @Text.figure.setter + def figure(self, fig): if self.arrow is not None: - self.arrow.set_figure(fig) + self.arrow.figure = fig if self.arrow_patch is not None: - self.arrow_patch.set_figure(fig) - Artist.set_figure(self, fig) + self.arrow_patch.figure = fig + Text.figure.__set__(self, fig) def update_positions(self, renderer): """"Update the pixel positions of the annotated point and the diff --git a/lib/mpl_toolkits/axes_grid/colorbar.py b/lib/mpl_toolkits/axes_grid/colorbar.py index 44c0b1936e75..3e8edeb95d3d 100644 --- a/lib/mpl_toolkits/axes_grid/colorbar.py +++ b/lib/mpl_toolkits/axes_grid/colorbar.py @@ -802,7 +802,7 @@ def make_axes(parent, **kw): panchor = (0.5, 0.0) parent.set_position(pb1) parent.set_anchor(panchor) - fig = parent.get_figure() + fig = parent.figure cax = fig.add_axes(pbcb) cax.set_aspect(aspect, anchor=anchor, adjustable='box') return cax, kw diff --git a/lib/mpl_toolkits/axes_grid1/axes_divider.py b/lib/mpl_toolkits/axes_grid1/axes_divider.py index 79424ecead6d..03de73737a79 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_divider.py +++ b/lib/mpl_toolkits/axes_grid1/axes_divider.py @@ -497,7 +497,7 @@ def __init__(self, axes, xref=None, yref=None): else: self._yref = yref - Divider.__init__(self, fig=axes.get_figure(), pos=None, + Divider.__init__(self, fig=axes.figure, pos=None, horizontal=[self._xref], vertical=[self._yref], aspect=None, anchor="C") @@ -512,7 +512,7 @@ def _get_new_axes(self, **kwargs): else: axes_class = type(axes) - ax = axes_class(axes.get_figure(), + ax = axes_class(axes.figure, axes.get_position(original=True), **kwargs) return ax diff --git a/lib/mpl_toolkits/axes_grid1/axes_rgb.py b/lib/mpl_toolkits/axes_grid1/axes_rgb.py index d00e3b8418e6..1f6ad936da10 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_rgb.py +++ b/lib/mpl_toolkits/axes_grid1/axes_rgb.py @@ -34,7 +34,7 @@ def make_rgb_axes(ax, pad=0.01, axes_class=None, add_all=True): axes_class = locatable_axes_factory(type(ax)) for ny in [4, 2, 0]: - ax1 = axes_class(ax.get_figure(), + ax1 = axes_class(ax.figure, ax.get_position(original=True), sharex=ax, sharey=ax) locator = divider.new_locator(nx=2, ny=ny) @@ -50,7 +50,7 @@ def make_rgb_axes(ax, pad=0.01, axes_class=None, add_all=True): ax_rgb.append(ax1) if add_all: - fig = ax.get_figure() + fig = ax.figure for ax1 in ax_rgb: fig.add_axes(ax1) @@ -144,7 +144,7 @@ def __init__(self, *kl, **kwargs): ax_rgb = [] for ny in [4, 2, 0]: - ax1 = axes_class(ax.get_figure(), + ax1 = axes_class(ax.figure, ax.get_position(original=True), sharex=ax, sharey=ax, **kwargs) locator = divider.new_locator(nx=2, ny=ny) @@ -156,7 +156,7 @@ def __init__(self, *kl, **kwargs): self.R, self.G, self.B = ax_rgb if add_all: - fig = ax.get_figure() + fig = ax.figure fig.add_axes(ax) self.add_RGB_to_figure() @@ -177,9 +177,9 @@ def _config_axes(self, line_color='w', marker_edge_color='w'): def add_RGB_to_figure(self): """Add the red, green and blue axes to the RGB composite's axes figure """ - self.RGB.get_figure().add_axes(self.R) - self.RGB.get_figure().add_axes(self.G) - self.RGB.get_figure().add_axes(self.B) + self.RGB.figure.add_axes(self.R) + self.RGB.figure.add_axes(self.G) + self.RGB.figure.add_axes(self.B) def imshow_rgb(self, r, g, b, **kwargs): """Create the four images {rgb, r, g, b} diff --git a/lib/mpl_toolkits/axes_grid1/axes_size.py b/lib/mpl_toolkits/axes_grid1/axes_size.py index 946db5157dc6..10508cb37f63 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_size.py +++ b/lib/mpl_toolkits/axes_grid1/axes_size.py @@ -162,7 +162,7 @@ def get_size(self, renderer): bb = a.get_window_extent(renderer) w_list.append(bb.width) h_list.append(bb.height) - dpi = a.get_figure().get_dpi() + dpi = a.figure.get_dpi() if self._w_or_h == "width": abs_size = max(w_list)/dpi elif self._w_or_h == "height": @@ -188,7 +188,7 @@ def get_size(self, renderer): for a in self._artist_list: bb = a.get_window_extent(renderer) w_list.append(bb.width) - dpi = a.get_figure().get_dpi() + dpi = a.figure.get_dpi() abs_size = max(w_list)/dpi return rel_size, abs_size @@ -212,7 +212,7 @@ def get_size(self, renderer): for a in self._artist_list: bb = a.get_window_extent(renderer) h_list.append(bb.height) - dpi = a.get_figure().get_dpi() + dpi = a.figure.get_dpi() abs_size = max(h_list)/dpi return rel_size, abs_size diff --git a/lib/mpl_toolkits/axes_grid1/colorbar.py b/lib/mpl_toolkits/axes_grid1/colorbar.py index 4268502dbd75..85887bdc735b 100644 --- a/lib/mpl_toolkits/axes_grid1/colorbar.py +++ b/lib/mpl_toolkits/axes_grid1/colorbar.py @@ -803,7 +803,7 @@ def make_axes(parent, **kw): panchor = (0.5, 0.0) parent.set_position(pb1) parent.set_anchor(panchor) - fig = parent.get_figure() + fig = parent.figure cax = fig.add_axes(pbcb) cax.set_aspect(aspect, anchor=anchor, adjustable='box') return cax, kw diff --git a/lib/mpl_toolkits/axisartist/axis_artist.py b/lib/mpl_toolkits/axisartist/axis_artist.py index 6b1904673f71..326dc216b38e 100644 --- a/lib/mpl_toolkits/axisartist/axis_artist.py +++ b/lib/mpl_toolkits/axisartist/axis_artist.py @@ -1413,7 +1413,7 @@ def _init_label(self, **kw): axis_direction=self._axis_direction, ) - self.label.set_figure(self.axes.figure) + self.label.figure = self.axes.figure labelpad = kw.get("labelpad", 5) self.label.set_pad(labelpad) diff --git a/lib/mpl_toolkits/axisartist/floating_axes.py b/lib/mpl_toolkits/axisartist/floating_axes.py index c7c03c137340..748236e04231 100644 --- a/lib/mpl_toolkits/axisartist/floating_axes.py +++ b/lib/mpl_toolkits/axisartist/floating_axes.py @@ -496,7 +496,7 @@ def cla(self): patch = self._axes_class_floating._gen_axes_patch(self) - patch.set_figure(self.figure) + patch.figure = self.figure patch.set_visible(False) patch.set_transform(self.transAxes) From 58039d18c7e6f111c68a949d69d9de896bbe5117 Mon Sep 17 00:00:00 2001 From: Marin Gilles Date: Fri, 31 Jul 2015 23:53:41 +0200 Subject: [PATCH 3/5] cleanup commit --- lib/matplotlib/__init__.py | 1 + lib/matplotlib/axes/_base.py | 1 + lib/matplotlib/axes/_subplots.py | 11 ----------- lib/matplotlib/text.py | 2 -- 4 files changed, 2 insertions(+), 13 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 2e522a07ce9a..5e486f9cf6b0 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1500,6 +1500,7 @@ def test(verbosity=1): finally: if old_backend.lower() != 'agg': use(old_backend) + return success def deprecated_get_set(function, to_use): diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 20b2943eb5f3..e538a7b59998 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -517,6 +517,7 @@ def figure(self, fig): self.viewLim = mtransforms.Bbox.unit() self.transScale = mtransforms.TransformWrapper( mtransforms.IdentityTransform()) + self._set_lim_and_transforms() def _set_lim_and_transforms(self): diff --git a/lib/matplotlib/axes/_subplots.py b/lib/matplotlib/axes/_subplots.py index 83cc09fb198f..a72b4c9b403f 100644 --- a/lib/matplotlib/axes/_subplots.py +++ b/lib/matplotlib/axes/_subplots.py @@ -36,8 +36,6 @@ def __init__(self, fig, *args, **kwargs): """ self._figure = fig - # self._figure = None - # self.figure = fig if len(args) == 1: if isinstance(args[0], SubplotSpec): @@ -88,15 +86,6 @@ def not_subplotbase(c): self.__getstate__()] return tuple(r) - # @property - # def figure(self): - # """:class:`~matplotlib.figure.Figure` the subplot is set to""" - # return self._figure - - # @figure.setter - # def figure(self, fig): - # self._figure = fig - def get_geometry(self): """get the subplot geometry, e.g., 2,2,3""" rows, cols, num1, num2 = self.get_subplotspec().get_geometry() diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 25d794c43161..e6b53ca8c664 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -1630,7 +1630,6 @@ def set_figure(self, fig): def figure(self, fig): Text.figure.__set__(self, fig) - docstring.interpd.update(TextWithDash=artist.kwdoc(TextWithDash)) @@ -2027,7 +2026,6 @@ def __init__(self, s, xy, xy, xycoords=xycoords, annotation_clip=annotation_clip) - # warn about wonky input data if (xytext is None and textcoords is not None and From be32a08135580f3182146cfdea868c3b496bdd23 Mon Sep 17 00:00:00 2001 From: Marin Gilles Date: Sat, 1 Aug 2015 00:39:58 +0200 Subject: [PATCH 4/5] getters and setters deprecated --- lib/matplotlib/__init__.py | 8 +++++--- lib/matplotlib/artist.py | 4 ++-- lib/matplotlib/axes/_base.py | 6 +----- lib/matplotlib/offsetbox.py | 2 ++ lib/matplotlib/quiver.py | 1 + lib/matplotlib/table.py | 1 + lib/matplotlib/text.py | 2 ++ 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 5e486f9cf6b0..4bb1a4863e02 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1503,19 +1503,21 @@ def test(verbosity=1): return success -def deprecated_get_set(function, to_use): +def deprecated_get_set(fclass, function, to_use): """Fuction to deprecate the getters and setter for a class argument. Parameter --------- + - fclass: class + The class of the function to deprecate - function: function The function to deprecate. - to_use: string The argument to use instead of the deprecated function """ - msg = "{} is deprecated, please use the `{}` argument" - msg = msg.format(function.__name__, to_use) + msg = "{}.{} is deprecated, please use the `{}` argument" + msg = msg.format(fclass.__name__, function.__name__, to_use) warnings.warn(msg, mplDeprecation, stacklevel=1) test.__test__ = False # nose: this function is not a test diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index be0c4ff1494e..8cb813529ae6 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -614,7 +614,7 @@ def get_figure(self): Return the :class:`~matplotlib.figure.Figure` instance the artist belongs to. """ - deprecated_get_set(self.get_figure, "figure") + deprecated_get_set(self.__class__, self.get_figure, "figure") return self.figure def set_figure(self, fig): @@ -624,7 +624,7 @@ def set_figure(self, fig): ACCEPTS: a :class:`matplotlib.figure.Figure` instance """ - deprecated_get_set(self.set_figure, "figure") + deprecated_get_set(self.__class__, self.set_figure, "figure") self.figure = fig def set_clip_box(self, clipbox): diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e538a7b59998..7dd447d927c4 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -500,13 +500,9 @@ def set_figure(self, fig): accepts a class:`~matplotlib.figure.Figure` instance """ - # import ipdb; ipdb.set_trace() + deprecated_get_set(self.__class__, self.set_figure, "figure") self.figure = fig - @martist.Artist.figure.getter - def figure(self): - return self._figure - @martist.Artist.figure.setter def figure(self, fig): martist.Artist.figure.__set__(self, fig) diff --git a/lib/matplotlib/offsetbox.py b/lib/matplotlib/offsetbox.py index bf847896351d..427a53bdc566 100644 --- a/lib/matplotlib/offsetbox.py +++ b/lib/matplotlib/offsetbox.py @@ -183,6 +183,7 @@ def set_figure(self, fig): accepts a class:`~matplotlib.figure.Figure` instance """ + deprecated_get_set(self.__class__, self.set_figure, "figure") self.figure = fig @martist.Artist.figure.setter @@ -1464,6 +1465,7 @@ def get_children(self): return children def set_figure(self, fig): + deprecated_get_set(self.__class__, self.set_figure, "figure") self.figure = fig @martist.Artist.figure.setter diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index 255faa5748a2..263df6af65b3 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -351,6 +351,7 @@ def _set_transform(self): raise ValueError('unrecognized coordinates') def set_figure(self, fig): + deprecated_get_set(self.__class__, self.set_figure, "figure") self.figure = fig @martist.Artist.figure.setter diff --git a/lib/matplotlib/table.py b/lib/matplotlib/table.py index 98e782699216..a78b710cce66 100644 --- a/lib/matplotlib/table.py +++ b/lib/matplotlib/table.py @@ -71,6 +71,7 @@ def set_transform(self, trans): self.stale = True def set_figure(self, fig): + deprecated_get_set(self.__class__, self.set_figure, "figure") self.figure = fig @Rectangle.figure.setter diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index e6b53ca8c664..6832e664ca5f 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -1624,6 +1624,7 @@ def set_figure(self, fig): ACCEPTS: a :class:`matplotlib.figure.Figure` instance """ + deprecated_get_set(self.__class__, self.set_figure, "figure") self.figure = fig @Text.figure.setter @@ -2084,6 +2085,7 @@ def anncoords(self, coords): self._textcoords = coords def set_figure(self, fig): + deprecated_get_set(self.__class__, self.set_figure, "figure") self.figure = fig @Text.figure.setter From f48018bbb38e4443db8a3dd119a826b15defb612 Mon Sep 17 00:00:00 2001 From: Marin Gilles Date: Sat, 1 Aug 2015 00:56:20 +0200 Subject: [PATCH 5/5] pep8 fix --- lib/matplotlib/__init__.py | 2 ++ lib/matplotlib/artist.py | 1 - lib/matplotlib/offsetbox.py | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 4bb1a4863e02..2d227c6b12f9 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1503,6 +1503,7 @@ def test(verbosity=1): return success + def deprecated_get_set(fclass, function, to_use): """Fuction to deprecate the getters and setter for a class argument. @@ -1520,6 +1521,7 @@ def deprecated_get_set(fclass, function, to_use): msg = msg.format(fclass.__name__, function.__name__, to_use) warnings.warn(msg, mplDeprecation, stacklevel=1) + test.__test__ = False # nose: this function is not a test verbose.report('matplotlib version %s' % __version__) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 8cb813529ae6..f4b69bd4ba37 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -608,7 +608,6 @@ def figure(self, fig): self.pchanged() self.stale = True - def get_figure(self): """ Return the :class:`~matplotlib.figure.Figure` instance the diff --git a/lib/matplotlib/offsetbox.py b/lib/matplotlib/offsetbox.py index 427a53bdc566..9dcda2e2b8f4 100644 --- a/lib/matplotlib/offsetbox.py +++ b/lib/matplotlib/offsetbox.py @@ -1475,7 +1475,6 @@ def figure(self, fig): self.offsetbox.figure = fig martist.Artist.figure.__set__(self, fig) - def set_fontsize(self, s=None): """ set fontsize in points pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy