From 190937839d810759d3459b3f862a2902227a444e Mon Sep 17 00:00:00 2001 From: Andres Gutierrrez Date: Sat, 2 Aug 2025 20:34:44 -0400 Subject: [PATCH 1/7] check xytext --- lib/matplotlib/text.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index acde4fb179a2..8037108373ca 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -5,6 +5,7 @@ import functools import logging import math +import numbers from numbers import Real import weakref @@ -1862,6 +1863,7 @@ def transform(renderer) -> Transform xy, xycoords=xycoords, annotation_clip=annotation_clip) + self.xytext = xytext # warn about wonky input data if (xytext is None and textcoords is not None and @@ -2027,7 +2029,12 @@ def draw(self, renderer): # docstring inherited if renderer is not None: self._renderer = renderer - if not self.get_visible() or not self._check_xy(renderer): + + visible = (self.get_visible() and + self._check_xy(renderer) and + self._check_xytext()) + + if not visible: return # Update text positions before `Text.draw` would, so that the # FancyArrowPatch is correctly positioned. @@ -2046,7 +2053,10 @@ def get_window_extent(self, renderer=None): # docstring inherited # This block is the same as in Text.get_window_extent, but we need to # set the renderer before calling update_positions(). - if not self.get_visible() or not self._check_xy(renderer): + visible = (self.get_visible() and + self._check_xy(renderer) and + self._check_xytext()) + if not visible: return Bbox.unit() if renderer is not None: self._renderer = renderer @@ -2072,4 +2082,10 @@ def get_tightbbox(self, renderer=None): return super().get_tightbbox(renderer) + def _check_xytext(self, renderer=None): + """Check whether the annotation at *xy_pixel* should be drawn.""" + valid = True + if all(isinstance(xyt, numbers.Number) for xyt in self.xytext): + valid = not np.isnan(self.xytext).any() + return valid _docstring.interpd.register(Annotation=Annotation.__init__.__doc__) From 07130be50aaf53e38e284c6fd478ae0348f740f1 Mon Sep 17 00:00:00 2001 From: Andres Gutierrrez Date: Sat, 2 Aug 2025 21:22:37 -0400 Subject: [PATCH 2/7] fix case xytext is None --- lib/matplotlib/text.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 8037108373ca..da14cb3e94aa 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -2085,6 +2085,9 @@ def get_tightbbox(self, renderer=None): def _check_xytext(self, renderer=None): """Check whether the annotation at *xy_pixel* should be drawn.""" valid = True + if self.xytext is None: + return valid + if all(isinstance(xyt, numbers.Number) for xyt in self.xytext): valid = not np.isnan(self.xytext).any() return valid From 562336443007a5f9cd76ebce12bb5b13d26913c8 Mon Sep 17 00:00:00 2001 From: Andres Gutierrrez Date: Sat, 2 Aug 2025 21:44:58 -0400 Subject: [PATCH 3/7] check_xytext finite --- lib/matplotlib/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index da14cb3e94aa..0544d1bc6f6c 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -2089,6 +2089,6 @@ def _check_xytext(self, renderer=None): return valid if all(isinstance(xyt, numbers.Number) for xyt in self.xytext): - valid = not np.isnan(self.xytext).any() + valid = not np.isnan(self.xytext).any() and np.isfinite(self.xytext).all() return valid _docstring.interpd.register(Annotation=Annotation.__init__.__doc__) From 5c979f85c391b39649978b9b19e56970c01946fb Mon Sep 17 00:00:00 2001 From: Andres Gutierrrez Date: Mon, 4 Aug 2025 19:22:16 -0400 Subject: [PATCH 4/7] raise ValueError for invalid xytext --- lib/matplotlib/text.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 0544d1bc6f6c..95a9ff574592 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -2030,9 +2030,9 @@ def draw(self, renderer): if renderer is not None: self._renderer = renderer - visible = (self.get_visible() and - self._check_xy(renderer) and - self._check_xytext()) + visible = self.get_visible() and self._check_xy(renderer) + + self._check_xytext() if not visible: return @@ -2053,9 +2053,10 @@ def get_window_extent(self, renderer=None): # docstring inherited # This block is the same as in Text.get_window_extent, but we need to # set the renderer before calling update_positions(). - visible = (self.get_visible() and - self._check_xy(renderer) and - self._check_xytext()) + visible = self.get_visible() and self._check_xy(renderer) + + self._check_xytext() + if not visible: return Bbox.unit() if renderer is not None: @@ -2085,10 +2086,16 @@ def get_tightbbox(self, renderer=None): def _check_xytext(self, renderer=None): """Check whether the annotation at *xy_pixel* should be drawn.""" valid = True + if self.xytext is None: return valid - if all(isinstance(xyt, numbers.Number) for xyt in self.xytext): - valid = not np.isnan(self.xytext).any() and np.isfinite(self.xytext).all() + coords = np.array(self.get_transform().transform(self.xytext)) + + if all(isinstance(xyt, numbers.Number) for xyt in coords): + valid = not np.isnan(coords).any() and np.isfinite(coords).all() + + if not valid: + raise ValueError("xytext coordinates must be finite numbers") return valid _docstring.interpd.register(Annotation=Annotation.__init__.__doc__) From f680e3f9f7ec2806f1a3e1b6c0f7b8a1771b5532 Mon Sep 17 00:00:00 2001 From: Andres Gutierrrez Date: Tue, 5 Aug 2025 17:50:49 -0400 Subject: [PATCH 5/7] fix transformation error --- lib/matplotlib/text.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 95a9ff574592..ece87d6304f1 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -2084,13 +2084,16 @@ def get_tightbbox(self, renderer=None): def _check_xytext(self, renderer=None): - """Check whether the annotation at *xy_pixel* should be drawn.""" + """Check whether the annotation text at *xy_pixel* should be drawn.""" valid = True if self.xytext is None: return valid - coords = np.array(self.get_transform().transform(self.xytext)) + try: + coords = np.array(self.get_transform().transform(self.xytext)) + except TypeError: + valid = False if all(isinstance(xyt, numbers.Number) for xyt in coords): valid = not np.isnan(coords).any() and np.isfinite(coords).all() From f64a90f476ef74d4d386f8081f5e58cdbe03b3da Mon Sep 17 00:00:00 2001 From: Andres Gutierrrez Date: Tue, 5 Aug 2025 18:19:16 -0400 Subject: [PATCH 6/7] fix unbound coords --- 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 ece87d6304f1..77477558fd35 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -2092,11 +2092,12 @@ def _check_xytext(self, renderer=None): try: coords = np.array(self.get_transform().transform(self.xytext)) + if all(isinstance(xyt, numbers.Number) for xyt in coords): + valid = not np.isnan(coords).any() and np.isfinite(coords).all() + except TypeError: valid = False - if all(isinstance(xyt, numbers.Number) for xyt in coords): - valid = not np.isnan(coords).any() and np.isfinite(coords).all() if not valid: raise ValueError("xytext coordinates must be finite numbers") From b03ea7bc2b2db4f5feccf115c49235f3aa0893cb Mon Sep 17 00:00:00 2001 From: Andres Gutierrrez Date: Tue, 5 Aug 2025 19:48:56 -0400 Subject: [PATCH 7/7] fix support for units --- lib/matplotlib/text.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 77477558fd35..23a27316b532 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -2091,13 +2091,19 @@ def _check_xytext(self, renderer=None): return valid try: + # transforming the coordinates coords = np.array(self.get_transform().transform(self.xytext)) if all(isinstance(xyt, numbers.Number) for xyt in coords): valid = not np.isnan(coords).any() and np.isfinite(coords).all() - except TypeError: - valid = False - + # If transformation fails, check raw coordinates + if all(isinstance(xyt, numbers.Number) for xyt in self.xytext): + is_numerical = not np.isnan(self.xytext).any() + finite = np.isfinite(self.xytext).all() + valid = is_numerical and finite + else: + # For non-number coordinates (like units), assume valid + valid = True if not valid: raise ValueError("xytext coordinates must be finite numbers") 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