Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9283c28

Browse files
committed
More properties aliases.
Also make it possible for Axes3D to define additional aliases on top of Axes.
1 parent f9e37f7 commit 9283c28

4 files changed

Lines changed: 17 additions & 21 deletions

File tree

doc/api/axes_api.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,7 @@ Appearance
240240
Axes.grid
241241

242242
Axes.get_facecolor
243-
Axes.get_fc
244-
245243
Axes.set_facecolor
246-
Axes.set_fc
247244

248245

249246
Property cycle

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ def _plot_args(self, tup, kwargs):
364364
for j in range(max(ncx, ncy))]
365365

366366

367+
@cbook._define_aliases({"facecolor": ["fc"]})
367368
class _AxesBase(martist.Artist):
368369
name = "rectilinear"
369370

@@ -1098,7 +1099,6 @@ def clear(self):
10981099
def get_facecolor(self):
10991100
"""Get the facecolor of the Axes."""
11001101
return self.patch.get_facecolor()
1101-
get_fc = get_facecolor
11021102

11031103
def set_facecolor(self, color):
11041104
"""
@@ -1111,7 +1111,6 @@ def set_facecolor(self, color):
11111111
self._facecolor = color
11121112
self.stale = True
11131113
return self.patch.set_facecolor(color)
1114-
set_fc = set_facecolor
11151114

11161115
def _set_title_offset_trans(self, title_offset_points):
11171116
"""

lib/matplotlib/cbook/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,10 +1884,17 @@ def method(self, *args, **kwargs):
18841884
raise ValueError(
18851885
"Neither getter nor setter exists for {!r}".format(prop))
18861886

1887-
if hasattr(cls, "_alias_map"):
1887+
def get_aliased_and_aliases(d):
1888+
return {*d, *(alias for aliases in d.values() for alias in aliases)}
1889+
1890+
preexisting_aliases = getattr(cls, "_alias_map", {})
1891+
conflicting = (get_aliased_and_aliases(preexisting_aliases)
1892+
& get_aliased_and_aliases(alias_d))
1893+
if conflicting:
18881894
# Need to decide on conflict resolution policy.
1889-
raise NotImplementedError("Parent class already defines aliases")
1890-
cls._alias_map = alias_d
1895+
raise NotImplementedError(
1896+
f"Parent class already defines conflicting aliases: {conflicting}")
1897+
cls._alias_map = {**preexisting_aliases, **alias_d}
18911898
return cls
18921899

18931900

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def unit_bbox():
3939
return box
4040

4141

42+
@cbook._define_aliases({
43+
"xlim3d": ["xlim"], "ylim3d": ["ylim"], "zlim3d": ["zlim"]})
4244
class Axes3D(Axes):
4345
"""
4446
3D axes object.
@@ -585,7 +587,6 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
585587
Set 3D x limits.
586588
587589
See :meth:`matplotlib.axes.Axes.set_xlim` for full documentation.
588-
589590
"""
590591
if right is None and np.iterable(left):
591592
left, right = left
@@ -637,15 +638,13 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
637638
other.figure.canvas.draw_idle()
638639
self.stale = True
639640
return left, right
640-
set_xlim = set_xlim3d
641641

642642
def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
643643
*, ymin=None, ymax=None):
644644
"""
645645
Set 3D y limits.
646646
647647
See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation.
648-
649648
"""
650649
if top is None and np.iterable(bottom):
651650
bottom, top = bottom
@@ -698,15 +697,13 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
698697
other.figure.canvas.draw_idle()
699698
self.stale = True
700699
return bottom, top
701-
set_ylim = set_ylim3d
702700

703701
def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
704702
*, zmin=None, zmax=None):
705703
"""
706704
Set 3D z limits.
707705
708706
See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation
709-
710707
"""
711708
if top is None and np.iterable(bottom):
712709
bottom, top = bottom
@@ -759,32 +756,28 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
759756
other.figure.canvas.draw_idle()
760757
self.stale = True
761758
return bottom, top
762-
set_zlim = set_zlim3d
763759

764760
def get_xlim3d(self):
765761
return tuple(self.xy_viewLim.intervalx)
766762
get_xlim3d.__doc__ = maxes.Axes.get_xlim.__doc__
767-
get_xlim = get_xlim3d
768-
if get_xlim.__doc__ is not None:
769-
get_xlim.__doc__ += """
763+
if get_xlim3d.__doc__ is not None:
764+
get_xlim3d.__doc__ += """
770765
.. versionchanged :: 1.1.0
771766
This function now correctly refers to the 3D x-limits
772767
"""
773768

774769
def get_ylim3d(self):
775770
return tuple(self.xy_viewLim.intervaly)
776771
get_ylim3d.__doc__ = maxes.Axes.get_ylim.__doc__
777-
get_ylim = get_ylim3d
778-
if get_ylim.__doc__ is not None:
779-
get_ylim.__doc__ += """
772+
if get_ylim3d.__doc__ is not None:
773+
get_ylim3d.__doc__ += """
780774
.. versionchanged :: 1.1.0
781775
This function now correctly refers to the 3D y-limits.
782776
"""
783777

784778
def get_zlim3d(self):
785779
'''Get 3D z limits.'''
786780
return tuple(self.zz_viewLim.intervalx)
787-
get_zlim = get_zlim3d
788781

789782
def get_zscale(self):
790783
"""

0 commit comments

Comments
 (0)