From 46a33f6b2e7b18d4bdc65ed1a9ea85c741422267 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 21 Feb 2025 20:12:46 -0500 Subject: [PATCH] Backport PR #29075: Add xaxis and yaxis attributes to Axes docs --- doc/api/axes_api.rst | 6 ++++++ lib/matplotlib/axes/_base.py | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/doc/api/axes_api.rst b/doc/api/axes_api.rst index bf2e30ea983c..06893dd95c57 100644 --- a/doc/api/axes_api.rst +++ b/doc/api/axes_api.rst @@ -262,6 +262,7 @@ Property cycle Axes.set_prop_cycle +.. _axes-api-axis: Axis / limits ============= @@ -269,11 +270,16 @@ Axis / limits .. For families of methods of the form {get,set}_{x,y}foo, try to list them in the order set_xfoo, get_xfoo, set_yfoo, get_yfoo +Axis access +----------- + .. autosummary:: :toctree: _as_gen :template: autosummary.rst :nosignatures: + Axes.xaxis + Axes.yaxis Axes.get_xaxis Axes.get_yaxis diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e45957fdd591..61d67d2791b4 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -566,6 +566,36 @@ class _AxesBase(martist.Artist): dataLim: mtransforms.Bbox """The bounding `.Bbox` enclosing all data displayed in the Axes.""" + xaxis: maxis.XAxis + """ + The `.XAxis` instance. + + Common axis-related configuration can be achieved through high-level wrapper + methods on Axes; e.g. `ax.set_xticks <.Axes.set_xticks>` is a shortcut for + `ax.xaxis.set_ticks <.Axis.set_ticks>`. The *xaxis* attribute gives direct + direct access to the underlying `~.axis.Axis` if you need more control. + + See also + + - :ref:`Axis wrapper methods on Axes ` + - :doc:`Axis API ` + """ + + yaxis: maxis.YAxis + """ + The `.YAxis` instance. + + Common axis-related configuration can be achieved through high-level wrapper + methods on Axes; e.g. `ax.set_yticks <.Axes.set_yticks>` is a shortcut for + `ax.yaxis.set_ticks <.Axis.set_ticks>`. The *yaxis* attribute gives direct + access to the underlying `~.axis.Axis` if you need more control. + + See also + + - :ref:`Axis wrapper methods on Axes ` + - :doc:`Axis API ` + """ + @property def _axis_map(self): """A mapping of axis names, e.g. 'x', to `Axis` instances.""" @@ -2218,7 +2248,7 @@ def get_xaxis(self): .. admonition:: Discouraged The use of this function is discouraged. You should instead - directly access the attribute ``ax.xaxis``. + directly access the attribute `~.Axes.xaxis`. """ return self.xaxis @@ -2229,7 +2259,7 @@ def get_yaxis(self): .. admonition:: Discouraged The use of this function is discouraged. You should instead - directly access the attribute ``ax.yaxis``. + directly access the attribute `~.Axes.yaxis`. """ return self.yaxis