diff --git a/doc/api/axes_api.rst b/doc/api/axes_api.rst index 030655458c26..6fd05a604347 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 e90bf7640c67..4b41cf462f80 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -565,6 +565,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 ` + """ + def __str__(self): return "{0}({1[0]:g},{1[1]:g};{1[2]:g}x{1[3]:g})".format( type(self).__name__, self._position.bounds) @@ -677,8 +707,9 @@ def __init__(self, fig, self._colorbars = [] self.spines = mspines.Spines.from_dict(self._gen_axes_spines()) - # this call may differ for non-sep axes, e.g., polar - self._init_axis() + self.xaxis = None # will be populated in _init_axis() + self.yaxis = None # will be populated in _init_axis() + self._init_axis() # this call may differ for non-sep axes, e.g., polar self._axis_map = { name: getattr(self, f"{name}axis") for name in self._axis_names } # A mapping of axis names, e.g. 'x', to `Axis` instances. @@ -2212,7 +2243,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 @@ -2223,7 +2254,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