From a75771b933b6c1a366e50871238e311ae4c40091 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Mon, 18 Sep 2023 13:37:10 +0200 Subject: [PATCH] Catch ValueError to support pytorch (and others) plotting --- lib/matplotlib/cbook.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index 80ec1612688b..f02486a0e280 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -1685,7 +1685,7 @@ def safe_first_element(obj): def _safe_first_finite(obj, *, skip_nonfinite=True): """ Return the first finite element in *obj* if one is available and skip_nonfinite is - True. Otherwise return the first element. + True. Otherwise, return the first element. This is a method for internal use. @@ -1697,7 +1697,7 @@ def safe_isfinite(val): return False try: return math.isfinite(val) - except TypeError: + except (TypeError, ValueError): pass try: return np.isfinite(val) if np.isscalar(val) else True