From 9283c288563aeb48d547849a8ff9ce0253956701 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 18 Sep 2019 12:46:49 +0200 Subject: [PATCH] More properties aliases. Also make it possible for Axes3D to define additional aliases on top of Axes. --- doc/api/axes_api.rst | 3 --- lib/matplotlib/axes/_base.py | 3 +-- lib/matplotlib/cbook/__init__.py | 13 ++++++++++--- lib/mpl_toolkits/mplot3d/axes3d.py | 19 ++++++------------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/doc/api/axes_api.rst b/doc/api/axes_api.rst index a3660fac3ba7..f3c30945375e 100644 --- a/doc/api/axes_api.rst +++ b/doc/api/axes_api.rst @@ -240,10 +240,7 @@ Appearance Axes.grid Axes.get_facecolor - Axes.get_fc - Axes.set_facecolor - Axes.set_fc Property cycle diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 6e683f8cb467..a81e14d479d3 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -364,6 +364,7 @@ def _plot_args(self, tup, kwargs): for j in range(max(ncx, ncy))] +@cbook._define_aliases({"facecolor": ["fc"]}) class _AxesBase(martist.Artist): name = "rectilinear" @@ -1098,7 +1099,6 @@ def clear(self): def get_facecolor(self): """Get the facecolor of the Axes.""" return self.patch.get_facecolor() - get_fc = get_facecolor def set_facecolor(self, color): """ @@ -1111,7 +1111,6 @@ def set_facecolor(self, color): self._facecolor = color self.stale = True return self.patch.set_facecolor(color) - set_fc = set_facecolor def _set_title_offset_trans(self, title_offset_points): """ diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index a6a163843a6a..d6b568dfccb3 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -1884,10 +1884,17 @@ def method(self, *args, **kwargs): raise ValueError( "Neither getter nor setter exists for {!r}".format(prop)) - if hasattr(cls, "_alias_map"): + def get_aliased_and_aliases(d): + return {*d, *(alias for aliases in d.values() for alias in aliases)} + + preexisting_aliases = getattr(cls, "_alias_map", {}) + conflicting = (get_aliased_and_aliases(preexisting_aliases) + & get_aliased_and_aliases(alias_d)) + if conflicting: # Need to decide on conflict resolution policy. - raise NotImplementedError("Parent class already defines aliases") - cls._alias_map = alias_d + raise NotImplementedError( + f"Parent class already defines conflicting aliases: {conflicting}") + cls._alias_map = {**preexisting_aliases, **alias_d} return cls diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 54454b4a16c7..6ef8a94e4435 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -39,6 +39,8 @@ def unit_bbox(): return box +@cbook._define_aliases({ + "xlim3d": ["xlim"], "ylim3d": ["ylim"], "zlim3d": ["zlim"]}) class Axes3D(Axes): """ 3D axes object. @@ -585,7 +587,6 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, Set 3D x limits. See :meth:`matplotlib.axes.Axes.set_xlim` for full documentation. - """ if right is None and np.iterable(left): left, right = left @@ -637,7 +638,6 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, other.figure.canvas.draw_idle() self.stale = True return left, right - set_xlim = set_xlim3d def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, *, ymin=None, ymax=None): @@ -645,7 +645,6 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, Set 3D y limits. See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation. - """ if top is None and np.iterable(bottom): bottom, top = bottom @@ -698,7 +697,6 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, other.figure.canvas.draw_idle() self.stale = True return bottom, top - set_ylim = set_ylim3d def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, *, zmin=None, zmax=None): @@ -706,7 +704,6 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, Set 3D z limits. See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation - """ if top is None and np.iterable(bottom): bottom, top = bottom @@ -759,14 +756,12 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, other.figure.canvas.draw_idle() self.stale = True return bottom, top - set_zlim = set_zlim3d def get_xlim3d(self): return tuple(self.xy_viewLim.intervalx) get_xlim3d.__doc__ = maxes.Axes.get_xlim.__doc__ - get_xlim = get_xlim3d - if get_xlim.__doc__ is not None: - get_xlim.__doc__ += """ + if get_xlim3d.__doc__ is not None: + get_xlim3d.__doc__ += """ .. versionchanged :: 1.1.0 This function now correctly refers to the 3D x-limits """ @@ -774,9 +769,8 @@ def get_xlim3d(self): def get_ylim3d(self): return tuple(self.xy_viewLim.intervaly) get_ylim3d.__doc__ = maxes.Axes.get_ylim.__doc__ - get_ylim = get_ylim3d - if get_ylim.__doc__ is not None: - get_ylim.__doc__ += """ + if get_ylim3d.__doc__ is not None: + get_ylim3d.__doc__ += """ .. versionchanged :: 1.1.0 This function now correctly refers to the 3D y-limits. """ @@ -784,7 +778,6 @@ def get_ylim3d(self): def get_zlim3d(self): '''Get 3D z limits.''' return tuple(self.zz_viewLim.intervalx) - get_zlim = get_zlim3d def get_zscale(self): """