Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c5a1c48

Browse filesBrowse files
anntzerMeeseeksDev[bot]
authored andcommitted
Backport PR #9295: In text, warn and return instead of raise exception for non-finite x, y
1 parent 0493add commit c5a1c48
Copy full SHA for c5a1c48

File tree

Expand file treeCollapse file tree

2 files changed

+13
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-3
lines changed

‎lib/matplotlib/tests/test_text.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_text.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,10 @@ def test_two_2line_texts(spacing1, spacing2):
441441
assert box1.height == box2.height
442442
else:
443443
assert box1.height != box2.height
444+
445+
446+
def test_nonfinite_pos():
447+
fig, ax = plt.subplots()
448+
ax.text(0, np.nan, 'nan')
449+
ax.text(np.inf, 0, 'inf')
450+
fig.canvas.draw()

‎lib/matplotlib/text.py

Copy file name to clipboardExpand all lines: lib/matplotlib/text.py
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import matplotlib.artist as artist
2121
from matplotlib.artist import Artist
2222
from matplotlib.cbook import maxdict
23-
from matplotlib import docstring
23+
from matplotlib import docstring, verbose
2424
from matplotlib.font_manager import FontProperties
2525
from matplotlib.patches import FancyBboxPatch
2626
from matplotlib.patches import FancyArrowPatch, Rectangle
@@ -759,9 +759,12 @@ def draw(self, renderer):
759759
# position in Text, and dash position in TextWithDash:
760760
posx = float(textobj.convert_xunits(textobj._x))
761761
posy = float(textobj.convert_yunits(textobj._y))
762-
if not np.isfinite(posx) or not np.isfinite(posy):
763-
raise ValueError("posx and posy should be finite values")
764762
posx, posy = trans.transform_point((posx, posy))
763+
if not np.isfinite(posx) or not np.isfinite(posy):
764+
verbose.report("x and y are not finite values for text "
765+
"string '{}'. Not rendering "
766+
"text.".format(self.get_text()), 'helpful')
767+
return
765768
canvasw, canvash = renderer.get_canvas_width_height()
766769

767770
# draw the FancyBboxPatch

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.