Skip to content

Commit 48f8235

Browse files
committed
FIX: axhline() / axvline() now always do autoscaling
Closes matplotlib#14651. As they are regularly added wih `add_line()`, they were always added to the data limits, but autoscaling was only updated under certain conditions, which led to an inconsistent state. See matplotlib#14651 (comment) Because of the inconsistent state, I'll classify this as a bug fix and justify that change can happen immediately without a deprecation.
1 parent fee65f1 commit 48f8235

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
``avhline()`` / ``axvline()`` always trigger autoscaling
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
`~.axes.Axes.hline` and `~.axes.Axes.vline` now always trigger autoscaling,
4+
like most other plotting functions.
5+
6+
Previously, autoscaling was not executed when the lines were already in the
7+
view limits; i.e. they were still visible, but margins were not expanded.
8+
The lines were still added to the data limits so that any subsequent,
9+
explicitly called or through another plotting function, would only then
10+
take the lines into account for margins.

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -818,14 +818,14 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs):
818818

819819
# Strip away the units for comparison with non-unitized bounds.
820820
yy, = self._process_unit_info([("y", y)], kwargs)
821-
scaley = (yy < ymin) or (yy > ymax)
822821

823822
trans = self.get_yaxis_transform(which='grid')
824823
l = mlines.Line2D([xmin, xmax], [y, y], transform=trans, **kwargs)
825824
self.add_line(l)
826825
l.get_path()._interpolation_steps = mpl.axis.GRIDLINE_INTERPOLATION_STEPS
827-
if scaley:
828-
self._request_autoscale_view("y")
826+
827+
self._request_autoscale_view("y")
828+
829829
return l
830830

831831
@_docstring.interpd
@@ -901,14 +901,14 @@ def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
901901

902902
# Strip away the units for comparison with non-unitized bounds.
903903
xx, = self._process_unit_info([("x", x)], kwargs)
904-
scalex = (xx < xmin) or (xx > xmax)
905904

906905
trans = self.get_xaxis_transform(which='grid')
907906
l = mlines.Line2D([x, x], [ymin, ymax], transform=trans, **kwargs)
908907
self.add_line(l)
909908
l.get_path()._interpolation_steps = mpl.axis.GRIDLINE_INTERPOLATION_STEPS
910-
if scalex:
911-
self._request_autoscale_view("x")
909+
910+
self._request_autoscale_view("x")
911+
912912
return l
913913

914914
@staticmethod

0 commit comments

Comments
 (0)