From 9d939f7e597d951805977ae699d8435f69724e7f Mon Sep 17 00:00:00 2001 From: Kevin Dalton Date: Mon, 7 Feb 2022 07:50:06 -0500 Subject: [PATCH 1/6] add Axes.vector --- lib/matplotlib/axes/_axes.py | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 39b1c751fae7..16d323e02d7a 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6772,6 +6772,45 @@ def hist(self, x, bins=None, range=None, density=False, weights=None, else "list[Polygon]") return tops, bins, cbook.silent_list(patch_type, patches) + def vector(self, dx, dy, x=0., y=0., **kwargs): + """ + Plot an arrow indicating a vector. + + Parameters + ---------- + dx : float + The x-component of the vector + dy : float + The y-component of the vector + x : float (optional) + The x-coordinate of the vector's base if nonzero. + y : float (optional) + The y-coordinate of the vector's base if nonzero. + + Other Parameters + ---------------- + **kwargs + `~matplotlib.patches.FancyArrowPatch` properties + """ + posA = (x, y) + posB = (x + dx, y + dy) + + color = kwargs.pop("color", None) + if color is None: + color = self._get_lines.get_next_color() + vect = mpatches.FancyArrowPatch(posA, posB, color=color, **kwargs) + ms = vect._mutation_scale + stylekw = { + "head_length" : kwargs.get("head_length", 12) / ms, + "head_width" : kwargs.get("head_width", 12) / ms, + "tail_width" : kwargs.get("tail_width", 4) / ms, + } + vect.set_arrowstyle(kwargs.get("arrowstyle", "simple"), **stylekw) + self.add_patch(vect) + self.update_datalim([posA, posB]) + self._request_autoscale_view() + return vect + @_preprocess_data() def stairs(self, values, edges=None, *, orientation='vertical', baseline=0, fill=False, **kwargs): From 4371b2fd4db3aed490f7224cee12db0246846b9a Mon Sep 17 00:00:00 2001 From: Kevin Dalton Date: Wed, 9 Feb 2022 10:15:36 -0500 Subject: [PATCH 2/6] fix whitespace for flake8 --- lib/matplotlib/axes/_axes.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 16d323e02d7a..695cf44dd78d 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6774,23 +6774,23 @@ def hist(self, x, bins=None, range=None, density=False, weights=None, def vector(self, dx, dy, x=0., y=0., **kwargs): """ - Plot an arrow indicating a vector. + Plot an arrow indicating a vector. Parameters ---------- dx : float - The x-component of the vector + The x-component of the vector dy : float - The y-component of the vector + The y-component of the vector x : float (optional) - The x-coordinate of the vector's base if nonzero. + The x-coordinate of the vector's base if nonzero. y : float (optional) - The y-coordinate of the vector's base if nonzero. + The y-coordinate of the vector's base if nonzero. Other Parameters ---------------- **kwargs - `~matplotlib.patches.FancyArrowPatch` properties + `~matplotlib.patches.FancyArrowPatch` properties """ posA = (x, y) posB = (x + dx, y + dy) @@ -6801,9 +6801,9 @@ def vector(self, dx, dy, x=0., y=0., **kwargs): vect = mpatches.FancyArrowPatch(posA, posB, color=color, **kwargs) ms = vect._mutation_scale stylekw = { - "head_length" : kwargs.get("head_length", 12) / ms, - "head_width" : kwargs.get("head_width", 12) / ms, - "tail_width" : kwargs.get("tail_width", 4) / ms, + "head_length": kwargs.get("head_length", 12) / ms, + "head_width": kwargs.get("head_width", 12) / ms, + "tail_width": kwargs.get("tail_width", 4) / ms, } vect.set_arrowstyle(kwargs.get("arrowstyle", "simple"), **stylekw) self.add_patch(vect) From c82b32efb649bec4231ed0670e48a7cc4541331e Mon Sep 17 00:00:00 2001 From: Kevin Dalton Date: Wed, 9 Feb 2022 13:54:18 -0500 Subject: [PATCH 3/6] fixed docstring indentation --- lib/matplotlib/axes/_axes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 6b1a711b8e67..d7d14ed7be8b 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6784,13 +6784,13 @@ def vector(self, dx, dy, x=0., y=0., **kwargs): Parameters ---------- dx : float - The x-component of the vector + The x-component of the vector dy : float - The y-component of the vector + The y-component of the vector x : float (optional) - The x-coordinate of the vector's base if nonzero. + The x-coordinate of the vector's base if nonzero. y : float (optional) - The y-coordinate of the vector's base if nonzero. + The y-coordinate of the vector's base if nonzero. Other Parameters ---------------- From 2fdae0b51d43a236c7d42b4908a6b6a3fbdae4da Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Wed, 25 Jan 2023 04:29:10 -0500 Subject: [PATCH 4/6] update vector signature --- lib/matplotlib/axes/_axes.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index d7d14ed7be8b..acfcd5f606b4 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6777,42 +6777,45 @@ def hist(self, x, bins=None, range=None, density=False, weights=None, else "list[Polygon]") return tops, bins, cbook.silent_list(patch_type, patches) - def vector(self, dx, dy, x=0., y=0., **kwargs): + def vector(self, start, *, delta=None, end=None, **kwargs): """ Plot an arrow indicating a vector. Parameters ---------- - dx : float - The x-component of the vector - dy : float - The y-component of the vector - x : float (optional) - The x-coordinate of the vector's base if nonzero. - y : float (optional) - The y-coordinate of the vector's base if nonzero. + start : (float, float) + The base point of the vector. + delta : (float, float) + The delta (deltaX, deltaY) from the start to the end of the vector. + Incompatible with *end* + end : float (optional) + The end point of the vector. Incompatible with *delta* Other Parameters ---------------- **kwargs `~matplotlib.patches.FancyArrowPatch` properties """ - posA = (x, y) - posB = (x + dx, y + dy) + if (delta is None) ^ (end is None): + raise ValueError("Exactly one *delta* or *end* must be Non-Zero") + if end is None: + end = np.asanyarray(start) + np.asanyarray(delta) color = kwargs.pop("color", None) if color is None: color = self._get_lines.get_next_color() - vect = mpatches.FancyArrowPatch(posA, posB, color=color, **kwargs) + vect = mpatches.FancyArrowPatch(start, end, color=color, **kwargs) ms = vect._mutation_scale stylekw = { "head_length": kwargs.get("head_length", 12) / ms, "head_width": kwargs.get("head_width", 12) / ms, "tail_width": kwargs.get("tail_width", 4) / ms, + "shrinkA": kwargs.get("shrinkA", 0), + "shrinkB": kwargs.get("shrinkB", 0), } vect.set_arrowstyle(kwargs.get("arrowstyle", "simple"), **stylekw) self.add_patch(vect) - self.update_datalim([posA, posB]) + self.update_datalim([start, end]) self._request_autoscale_view() return vect From acbfee78fcb77786d39d8de35564bc01a9ead86e Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Wed, 25 Jan 2023 04:40:41 -0500 Subject: [PATCH 5/6] add set/get delta to FancyArrowPatch --- lib/matplotlib/patches.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 894717dcdd3e..d6700f5fa2c9 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -4378,6 +4378,28 @@ def set_positions(self, posA, posB): self._posA_posB[1] = posB self.stale = True + def set_delta(self, delta): + """ + Set the end position by the delta from the start (posA). + + Parameters + ---------- + delta : (float, float) + The delta between the arrow tail and head. + """ + self._posA_posB[1] = self._posA_posB[0] + delta + self.stale = True + + def get_delta(self): + """ + Get the delta between the end and start positions. + + Returns + ------- + np.array + """ + return np.asanyarray(self._posA_posB[1] - self._posA_posB[0]) + def set_patchA(self, patchA): """ Set the tail patch. From 91d7e51e4d50c65b64567a09e333b8f79e3bd61f Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Wed, 25 Jan 2023 07:42:57 -0500 Subject: [PATCH 6/6] fix: small bugfixes to vector logic --- lib/matplotlib/axes/_axes.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index acfcd5f606b4..faed03104c72 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6796,7 +6796,7 @@ def vector(self, start, *, delta=None, end=None, **kwargs): **kwargs `~matplotlib.patches.FancyArrowPatch` properties """ - if (delta is None) ^ (end is None): + if not((delta is None) ^ (end is None)): raise ValueError("Exactly one *delta* or *end* must be Non-Zero") if end is None: end = np.asanyarray(start) + np.asanyarray(delta) @@ -6804,14 +6804,16 @@ def vector(self, start, *, delta=None, end=None, **kwargs): color = kwargs.pop("color", None) if color is None: color = self._get_lines.get_next_color() - vect = mpatches.FancyArrowPatch(start, end, color=color, **kwargs) + shrinkA = kwargs.get("shrinkA", 0) + shrinkB = kwargs.get("shrinkB", 0) + vect = mpatches.FancyArrowPatch( + start, end, color=color, shrinkA=shrinkA, shrinkB=shrinkB, **kwargs + ) ms = vect._mutation_scale stylekw = { "head_length": kwargs.get("head_length", 12) / ms, "head_width": kwargs.get("head_width", 12) / ms, "tail_width": kwargs.get("tail_width", 4) / ms, - "shrinkA": kwargs.get("shrinkA", 0), - "shrinkB": kwargs.get("shrinkB", 0), } vect.set_arrowstyle(kwargs.get("arrowstyle", "simple"), **stylekw) self.add_patch(vect) 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