Skip to content

Commit 90794e4

Browse files
committed
autoscale arrow
1 parent 74ed294 commit 90794e4

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/api/next_api_changes/behaviour.rst

+4
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ Previously, it did not necessarily have such an attribute. A check for
1717
``hasattr(figure.canvas, "manager")`` should now be replaced by
1818
``figure.canvas.manager is not None`` (or ``getattr(figure.canvas, "manager", None) is not None``
1919
for back-compatibility).
20+
21+
Autoscale for arrow
22+
~~~~~~~~~~~~~~~~~~~
23+
Calling ax.arrow() will now autoscale the axes.

lib/matplotlib/axes/_axes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4938,7 +4938,8 @@ def arrow(self, x, y, dx, dy, **kwargs):
49384938
dy = self.convert_yunits(dy)
49394939

49404940
a = mpatches.FancyArrow(x, y, dx, dy, **kwargs)
4941-
self.add_artist(a)
4941+
self.add_patch(a)
4942+
self._request_autoscale_view()
49424943
return a
49434944

49444945
@docstring.copy(mquiver.QuiverKey.__init__)

lib/matplotlib/tests/test_axes.py

+7
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ def test_arrow_empty():
382382
ax.arrow(0, 0, 0, 0, head_length=0)
383383

384384

385+
def test_arrow_in_view():
386+
_, ax = plt.subplots()
387+
ax.arrow(1, 1, 1, 1)
388+
assert ax.get_xlim() == (0.8, 2.2)
389+
assert ax.get_ylim() == (0.8, 2.2)
390+
391+
385392
def test_annotate_default_arrow():
386393
# Check that we can make an annotation arrow with only default properties.
387394
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)