Skip to content

More properties aliases. #15288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions doc/api/axes_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,7 @@ Appearance
Axes.grid

Axes.get_facecolor
Axes.get_fc

Axes.set_facecolor
Axes.set_fc


Property cycle
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand Down
13 changes: 10 additions & 3 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
19 changes: 6 additions & 13 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def unit_bbox():
return box


@cbook._define_aliases({
"xlim3d": ["xlim"], "ylim3d": ["ylim"], "zlim3d": ["zlim"]})
class Axes3D(Axes):
"""
3D axes object.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -637,15 +638,13 @@ 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):
"""
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
Expand Down Expand Up @@ -698,15 +697,13 @@ 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):
"""
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
Expand Down Expand Up @@ -759,32 +756,28 @@ 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
"""

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.
"""

def get_zlim3d(self):
'''Get 3D z limits.'''
return tuple(self.zz_viewLim.intervalx)
get_zlim = get_zlim3d

def get_zscale(self):
"""
Expand Down