File tree 2 files changed +13
-3
lines changed 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -441,3 +441,10 @@ def test_two_2line_texts(spacing1, spacing2):
441
441
assert box1 .height == box2 .height
442
442
else :
443
443
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 ()
Original file line number Diff line number Diff line change 20
20
import matplotlib .artist as artist
21
21
from matplotlib .artist import Artist
22
22
from matplotlib .cbook import maxdict
23
- from matplotlib import docstring
23
+ from matplotlib import docstring , verbose
24
24
from matplotlib .font_manager import FontProperties
25
25
from matplotlib .patches import FancyBboxPatch
26
26
from matplotlib .patches import FancyArrowPatch , Rectangle
@@ -759,9 +759,12 @@ def draw(self, renderer):
759
759
# position in Text, and dash position in TextWithDash:
760
760
posx = float (textobj .convert_xunits (textobj ._x ))
761
761
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" )
764
762
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
765
768
canvasw , canvash = renderer .get_canvas_width_height ()
766
769
767
770
# draw the FancyBboxPatch
You can’t perform that action at this time.
0 commit comments