From f4e7d6c468f7ec04e7947e13d4ddc7c513f273fd Mon Sep 17 00:00:00 2001 From: Yong Cho Yin Date: Tue, 24 Mar 2020 16:22:28 -0400 Subject: [PATCH] autoscale arrow --- doc/api/next_api_changes/behaviour.rst | 4 ++++ lib/matplotlib/axes/_axes.py | 3 ++- lib/matplotlib/tests/test_axes.py | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/api/next_api_changes/behaviour.rst b/doc/api/next_api_changes/behaviour.rst index cc301b57088e..b562196427ad 100644 --- a/doc/api/next_api_changes/behaviour.rst +++ b/doc/api/next_api_changes/behaviour.rst @@ -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. diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 99ff6a765ead..91fa52f0cbeb 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -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__) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 2a4f415e212a..9c10f81b01c8 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -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() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy