Skip to content
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

Nan issue in text.py #4066

Closed
ffteja opened this issue Feb 5, 2015 · 1 comment · Fixed by #4535
Closed

Nan issue in text.py #4066

ffteja opened this issue Feb 5, 2015 · 1 comment · Fixed by #4535
Assignees
Milestone

Comments

@ffteja
Copy link
Contributor

ffteja commented Feb 5, 2015

In text.py, in function "draw", the values returned by the line "posx, posy = trans.transform_point((posx, posy))" can set Nan values into posx and pos variables. Thus, the following test in the function "if not np.isfinite(x) or not np.isfinite(y):" is too early as "x = x + posx" is called afterwards. Thus it wil crashes in the following call to the draw_text function :

The following python error occurred:
        ValueError('cannot convert float NaN to integer',)
File "/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 198, in draw_text
        font.get_image(), np.round(x - xd), np.round(y + yd) + 1, angle, gc)

Please find the patch below that just moves the test :

Index: /matplotlib-1.4.0/lib/matplotlib/text.py
===================================================================
--- /matplotlib-1.4.0/lib/matplotlib/text.py    (révision 78983)
+++ /matplotlib-1.4.0/lib/matplotlib/text.py    (copie de travail)
@@ -561,14 +561,15 @@
         angle = self.get_rotation()

         for line, wh, x, y in info:
-            if not np.isfinite(x) or not np.isfinite(y):
-                continue
-
             mtext = self if len(info) == 1 else None
             x = x + posx
             y = y + posy
             if renderer.flipy():
                 y = canvash - y
+                
+            if not np.isfinite(x) or not np.isfinite(y):
+                continue
+
             clean_line, ismath = self.is_math_text(line)

             if self.get_path_effects():

You can reproduce this configuration by zooming in a polar plot.

[tac edited for markup]

@tacaswell
Copy link
Member

@ffteja Can you make a pull request with that patch applied? Doing so makes it a bit easier on us to review (which in this case isn't a huge deal) and makes sure you get credit for your contribution.

@tacaswell tacaswell added this to the v1.5.x milestone Feb 6, 2015
This was referenced Mar 16, 2015
tacaswell pushed a commit to tacaswell/matplotlib that referenced this issue Jun 17, 2015
@tacaswell tacaswell self-assigned this Jun 17, 2015
tacaswell pushed a commit to tacaswell/matplotlib that referenced this issue Jun 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants