Skip to content

Commit 62412c0

Browse files
QuLogictimhoffm
authored andcommitted
Backport PR matplotlib#29075: Add xaxis and yaxis attributes to Axes docs
1 parent 4001203 commit 62412c0

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

‎doc/api/axes_api.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,24 @@ Property cycle
262262

263263
Axes.set_prop_cycle
264264

265+
.. _axes-api-axis:
265266

266267
Axis / limits
267268
=============
268269

269270
.. For families of methods of the form {get,set}_{x,y}foo, try to list them in
270271
the order set_xfoo, get_xfoo, set_yfoo, get_yfoo
271272
273+
Axis access
274+
-----------
275+
272276
.. autosummary::
273277
:toctree: _as_gen
274278
:template: autosummary.rst
275279
:nosignatures:
276280

281+
Axes.xaxis
282+
Axes.yaxis
277283
Axes.get_xaxis
278284
Axes.get_yaxis
279285

‎lib/matplotlib/axes/_base.py‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,36 @@ class _AxesBase(martist.Artist):
566566
dataLim: mtransforms.Bbox
567567
"""The bounding `.Bbox` enclosing all data displayed in the Axes."""
568568

569+
xaxis: maxis.XAxis
570+
"""
571+
The `.XAxis` instance.
572+
573+
Common axis-related configuration can be achieved through high-level wrapper
574+
methods on Axes; e.g. `ax.set_xticks <.Axes.set_xticks>` is a shortcut for
575+
`ax.xaxis.set_ticks <.Axis.set_ticks>`. The *xaxis* attribute gives direct
576+
direct access to the underlying `~.axis.Axis` if you need more control.
577+
578+
See also
579+
580+
- :ref:`Axis wrapper methods on Axes <axes-api-axis>`
581+
- :doc:`Axis API </api/axis_api>`
582+
"""
583+
584+
yaxis: maxis.YAxis
585+
"""
586+
The `.YAxis` instance.
587+
588+
Common axis-related configuration can be achieved through high-level wrapper
589+
methods on Axes; e.g. `ax.set_yticks <.Axes.set_yticks>` is a shortcut for
590+
`ax.yaxis.set_ticks <.Axis.set_ticks>`. The *yaxis* attribute gives direct
591+
access to the underlying `~.axis.Axis` if you need more control.
592+
593+
See also
594+
595+
- :ref:`Axis wrapper methods on Axes <axes-api-axis>`
596+
- :doc:`Axis API </api/axis_api>`
597+
"""
598+
569599
@property
570600
def _axis_map(self):
571601
"""A mapping of axis names, e.g. 'x', to `Axis` instances."""
@@ -686,9 +716,10 @@ def __init__(self, fig,
686716

687717
# this call may differ for non-sep axes, e.g., polar
688718
self._init_axis()
689-
if facecolor is None:
690-
facecolor = mpl.rcParams['axes.facecolor']
691-
self._facecolor = facecolor
719+
self._axis_map = {
720+
name: getattr(self, f"{name}axis") for name in self._axis_names
721+
} # A mapping of axis names, e.g. 'x', to `Axis` instances.
722+
self._facecolor = mpl._val_or_rc(facecolor, 'axes.facecolor')
692723
self._frameon = frameon
693724
self.set_axisbelow(mpl.rcParams['axes.axisbelow'])
694725

@@ -2218,7 +2249,7 @@ def get_xaxis(self):
22182249
.. admonition:: Discouraged
22192250
22202251
The use of this function is discouraged. You should instead
2221-
directly access the attribute ``ax.xaxis``.
2252+
directly access the attribute `~.Axes.xaxis`.
22222253
"""
22232254
return self.xaxis
22242255

@@ -2229,7 +2260,7 @@ def get_yaxis(self):
22292260
.. admonition:: Discouraged
22302261
22312262
The use of this function is discouraged. You should instead
2232-
directly access the attribute ``ax.yaxis``.
2263+
directly access the attribute `~.Axes.yaxis`.
22332264
"""
22342265
return self.yaxis
22352266

0 commit comments

Comments
 (0)