Skip to content

Autoscale for ax.arrow() #15392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/behaviour.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,7 @@ Shortcuts for closing all figures now also work for the classic toolbar.
There is no default shortcut any more because unintentionally closing all figures by a key press
might happen too easily. You can configure the shortcut yourself
using :rc:`keymap.quit_all`.

Autoscale for arrow
~~~~~~~~~~~~~~~~~~~
Calling ax.arrow() will now autoscale the axes.
3 changes: 2 additions & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4959,7 +4959,8 @@ def arrow(self, x, y, dx, dy, **kwargs):
dy = self.convert_yunits(dy)

a = mpatches.FancyArrow(x, y, dx, dy, **kwargs)
self.add_artist(a)
self.add_patch(a)
self._request_autoscale_view()
return a

@docstring.copy(mquiver.QuiverKey.__init__)
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,13 @@ def test_arrow_empty():
ax.arrow(0, 0, 0, 0, head_length=0)


def test_arrow_in_view():
_, ax = plt.subplots()
ax.arrow(1, 1, 1, 1)
assert ax.get_xlim() == (0.8, 2.2)
assert ax.get_ylim() == (0.8, 2.2)


def test_annotate_default_arrow():
# Check that we can make an annotation arrow with only default properties.
fig, ax = plt.subplots()
Expand Down