Skip to content
This repository

Crash with text.usetex=True and plt.annotate #1583

Merged
merged 3 commits into from over 1 year ago

3 participants

Jake Vanderplas Paul Ivanov Michael Droettboom
Jake Vanderplas

The following minimal example causes a crash on the current master:

import matplotlib
import matplotlib.pyplot as plt

matplotlib.rcParams['text.usetex'] = True
plt.annotate(" ", (0, 0), (1, 0), arrowprops=dict(arrowstyle='->'))

plt.show()

If " " is changed to "" (an empty string) or if the arrowprops argument is removed, then the crash doesn't happen. Here is the traceback:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__
    return self.func(*args)
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 276, in resize
    self.show()
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 348, in draw
    FigureCanvasAgg.draw(self)
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 439, in draw
    self.figure.draw(self.renderer)
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/figure.py", line 999, in draw
    func(*args)
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/axes.py", line 2093, in draw
    a.draw(renderer)
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/text.py", line 2031, in draw
    self.arrow_patch.draw(renderer)
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/patches.py", line 4001, in draw
    path, fillable = self.get_path_in_displaycoord()
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/patches.py", line 3949, in get_path_in_displaycoord
    shrinkB=self.shrinkB * dpi_cor
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/patches.py", line 2507, in __call__
    clipped_path = self._clip(path, patchA, patchB)
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/patches.py", line 2452, in _clip
    left, right = split_path_inout(path, insideA)
  File "/home/vanderplas/PythonEnv/pydev/local/lib/python2.7/site-packages/matplotlib/bezier.py", line 242, in split_path_inout
    ctl_points, command = next(path_iter)
StopIteration

I'm running ubuntu with python 2.7.3, and the following:

>>> matplotlib.__version__
'1.3.x'
>>> matplotlib.rcParams['backend']
'TkAgg'

I've seen the crash also using Agg.

Paul Ivanov
Collaborator

@mdboom's change fixes Jake's example for me, but still breaks if I use two spaces instead of just one.

 plt.annotate("  ", (0, 0), (1, 0), arrowprops=dict(arrowstyle='->'))

I added a commit to deal with those, will submit PR against Mike's branch with that

Michael Droettboom Merge pull request #12 from ivanov/annotate_space
more complete fix for #1583 (multiple spaces)
7e91d71
Michael Droettboom mdboom merged commit 422712d into from December 17, 2012
Michael Droettboom mdboom closed this December 17, 2012
Phil Elson pelson referenced this pull request from a commit in pelson/matplotlib January 09, 2014
Phil Elson Added a test for #1583 and fixed the underlying problem. ddf57b1
Phil Elson pelson referenced this pull request from a commit in pelson/matplotlib January 09, 2014
Phil Elson Added a test for #1583 and fixed the underlying problem. d93372b
Phil Elson pelson referenced this pull request from a commit in pelson/matplotlib January 09, 2014
Phil Elson Added a test for #1583 and fixed the underlying problem. 3a8eabb
Phil Elson pelson referenced this pull request from a commit in pelson/matplotlib January 09, 2014
Phil Elson Added case from #1583. cacf3ef
Phil Elson pelson referenced this pull request from a commit in pelson/matplotlib January 09, 2014
Phil Elson Added a test for #1583 and fixed the underlying problem. 19c8ec4
Phil Elson pelson referenced this pull request from a commit in pelson/matplotlib January 09, 2014
Phil Elson Added a test for #1583 and fixed the underlying problem. 368f82a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 2 authors.

Dec 11, 2012
Michael Droettboom Fix #1583: Crash with text.usetex=True and plt.annotate -- usetex bou…
…nding boxes are all NaNs when text is empty.
707edb5
Dec 14, 2012
Paul Ivanov more complete fix for #1583 (multiple spaces) 3b857ab
Dec 17, 2012
Michael Droettboom Merge pull request #12 from ivanov/annotate_space
more complete fix for #1583 (multiple spaces)
7e91d71
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 3 additions and 3 deletions. Show diff stats Hide diff stats

  1. 6  lib/matplotlib/text.py
6  lib/matplotlib/text.py
@@ -524,7 +524,7 @@ def draw(self, renderer):
524 524
         if renderer is not None:
525 525
             self._renderer = renderer
526 526
         if not self.get_visible(): return
527  
-        if self.get_text()=='': return
  527
+        if self.get_text().strip() == '': return
528 528
 
529 529
         renderer.open_group('text', self.get_gid())
530 530
 
@@ -740,7 +740,7 @@ def get_window_extent(self, renderer=None, dpi=None):
740 740
         if dpi is not None:
741 741
             dpi_orig = self.figure.dpi
742 742
             self.figure.dpi = dpi
743  
-        if self.get_text() == '':
  743
+        if self.get_text().strip() == '':
744 744
             tx, ty = self._get_xy_display()
745 745
             return Bbox.from_bounds(tx,ty,0,0)
746 746
 
@@ -1898,7 +1898,7 @@ def _update_position_xytext(self, renderer, xy_pixel):
1898 1898
                         props = props.copy() # don't want to alter the pad externally
1899 1899
                         pad = props.pop('pad', 4)
1900 1900
                         pad = renderer.points_to_pixels(pad)
1901  
-                        if self.get_text() == "":
  1901
+                        if self.get_text().strip() == "":
1902 1902
                             self.arrow_patch.set_patchA(None)
1903 1903
                             return
1904 1904
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.