From 124812fef50806b5eb7efad92df89ee31c1c44bb Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 22 Nov 2019 10:59:18 +0100 Subject: [PATCH 1/2] Move Text kwargs init to end of Annotation init. ... in case some kwargs (each of which is handled by calling a set_foo) need to refer to arrow_patch. --- lib/matplotlib/text.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 9d23ffb87c88..464cbebd5b40 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -1764,8 +1764,6 @@ def transform(renderer) -> Transform xytext = self.xy x, y = xytext - Text.__init__(self, x, y, text, **kwargs) - self.arrowprops = arrowprops if arrowprops is not None: @@ -1785,6 +1783,9 @@ def transform(renderer) -> Transform else: self.arrow_patch = None + # Must come last, as some kwargs may be propagated to arrow_patch. + Text.__init__(self, x, y, text, **kwargs) + def contains(self, event): inside, info = self._default_contains(event) if inside is not None: From 2f6eaf5a11c92c580999cb53618ed7803f28e782 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 22 Nov 2019 11:01:57 +0100 Subject: [PATCH 2/2] Trivial style fix. --- lib/matplotlib/text.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 464cbebd5b40..3e4a77245698 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -1765,21 +1765,16 @@ def transform(renderer) -> Transform x, y = xytext self.arrowprops = arrowprops - if arrowprops is not None: + arrowprops = arrowprops.copy() if "arrowstyle" in arrowprops: - arrowprops = self.arrowprops.copy() self._arrow_relpos = arrowprops.pop("relpos", (0.5, 0.5)) else: # modified YAArrow API to be used with FancyArrowPatch - shapekeys = ('width', 'headwidth', 'headlength', - 'shrink', 'frac') - arrowprops = dict() - for key, val in self.arrowprops.items(): - if key not in shapekeys: - arrowprops[key] = val # basic Patch properties - self.arrow_patch = FancyArrowPatch((0, 0), (1, 1), - **arrowprops) + for key in [ + 'width', 'headwidth', 'headlength', 'shrink', 'frac']: + arrowprops.pop(key, None) + self.arrow_patch = FancyArrowPatch((0, 0), (1, 1), **arrowprops) else: self.arrow_patch = None