8000 Backport PR #9295 on branch v2.1.x by lumberbot-app[bot] · Pull Request #9308 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Backport PR #9295 on branch v2.1.x #9308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,10 @@ def test_two_2line_texts(spacing1, spacing2):
assert box1.height == box2.height
else:
assert box1.height != box2.height


def test_nonfinite_pos():
fig, ax = plt.subplots()
ax.text(0, np.nan, 'nan')
ax.text(np.inf, 0, 'inf')
fig.canvas.draw()
9 changes: 6 additions & 3 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import matplotlib.artist as artist
from matplotlib.artist import Artist
from matplotlib.cbook import maxdict
from matplotlib import docstring
from matplotlib import docstring, verbose
from matplotlib.font_manager import FontProperties
from matplotlib.patches import FancyBboxPatch
from matplotlib.patches import FancyArrowPatch, Rectangle
Expand Down Expand Up @@ -759,9 +759,12 @@ def draw(self, renderer):
# position in Text, and dash position in TextWithDash:
posx = float(textobj.convert_xunits(textobj._x))
posy = float(textobj.convert_yunits(textobj._y))
if not np.isfinite(posx) or not np.isfinite(posy):
raise ValueError("posx and posy should be finite values")
posx, posy = trans.transform_point((posx, posy))
if not np.isfinite(posx) or not np.isfinite(posy):
verbose.report("x and y are not finite values for text "
"string '{}'. Not rendering "
"text.".format(self.get_text()), 'helpful')
return
canvasw, canvash = renderer.get_canvas_width_height()

# draw the FancyBboxPatch
Expand Down
0