From 61d019b30ea44863451685f05938cd549fd174d4 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Wed, 14 Aug 2024 14:38:26 +0200 Subject: [PATCH] DOC: Clarify axhline() uses axes coordinates Closes #28612. --- .../artists/transforms_tutorial.py | 1 + lib/matplotlib/axes/_axes.py | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/galleries/users_explain/artists/transforms_tutorial.py b/galleries/users_explain/artists/transforms_tutorial.py index 8eed53c812b8..0be5fa3c2e21 100644 --- a/galleries/users_explain/artists/transforms_tutorial.py +++ b/galleries/users_explain/artists/transforms_tutorial.py @@ -22,6 +22,7 @@ :class:`~matplotlib.figure.Figure` instance, and ``subfigure`` is a :class:`~matplotlib.figure.SubFigure` instance. +.. _coordinate-systems: +----------------+-----------------------------------+-----------------------------+ |Coordinate |Description |Transformation object | diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 598a954f8819..243c175a1e5f 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -767,20 +767,25 @@ def annotate(self, text, xy, xytext=None, xycoords='data', textcoords=None, @_docstring.dedent_interpd def axhline(self, y=0, xmin=0, xmax=1, **kwargs): """ - Add a horizontal line across the Axes. + Add a horizontal line spanning the whole or fraction of the Axes. + + Note: If you want to set x-limits in data coordinates, use + `~.Axes.hlines` instead. Parameters ---------- y : float, default: 0 - y position in data coordinates of the horizontal line. + y position in :ref:`data coordinates `. xmin : float, default: 0 - Should be between 0 and 1, 0 being the far left of the plot, 1 the - far right of the plot. + The start x-position in :ref:`axes coordinates `. + Should be between 0 and 1, 0 being the far left of the plot, + 1 the far right of the plot. xmax : float, default: 1 - Should be between 0 and 1, 0 being the far left of the plot, 1 the - far right of the plot. + The end x-position in :ref:`axes coordinates `. + Should be between 0 and 1, 0 being the far left of the plot, + 1 the far right of the plot. Returns ------- @@ -836,18 +841,23 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs): @_docstring.dedent_interpd def axvline(self, x=0, ymin=0, ymax=1, **kwargs): """ - Add a vertical line across the Axes. + Add a vertical line spanning the whole or fraction of the Axes. + + Note: If you want to set y-limits in data coordinates, use + `~.Axes.vlines` instead. Parameters ---------- x : float, default: 0 - x position in data coordinates of the vertical line. + y position in :ref:`data coordinates `. ymin : float, default: 0 + The start y-position in :ref:`axes coordinates `. Should be between 0 and 1, 0 being the bottom of the plot, 1 the top of the plot. ymax : float, default: 1 + The end y-position in :ref:`axes coordinates `. Should be between 0 and 1, 0 being the bottom of the plot, 1 the top of the plot.