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

plt.xkcd() gives an error when a plt.text() is added with two line breaks "\n\n" #2687

Closed
saullocastro opened this issue Dec 17, 2013 · 2 comments

Comments

@saullocastro
Copy link

This issue is described in this Stackoverflow question:

http://stackoverflow.com/q/20637259/832621

# -*- coding: utf-8 -*-
from matplotlib import pyplot as plt
import numpy as np

plt.xkcd()

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.text(4, 400, '-> 1 Pig ~ 150 kg\n\n-> Butching => 80 to 100 kg meat')
plt.axis([0, 7, 0, 2000])
plt.plot([0,1,2,3,4,5], [0,400,800,1200,1600, 2000])
ax.set_ylim([0, 2000])
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
plt.show()

And I could reproduce on my system. If "\n\n" is replaced by "\n" or if plt.xkcd() is commented it works.

Windows 7 64 bit
Matplotlib 1.3.0
Numpy 1.7.1
Python 2.7 64 bit

@pelson
Copy link
Member

pelson commented Dec 18, 2013

A quick hack of the textpath module fixed the issue for me:

--- a/lib/matplotlib/textpath.py
+++ b/lib/matplotlib/textpath.py
@@ -157,6 +157,9 @@ class TextToPath(object):
             verts.extend(verts1)
             codes.extend(codes1)

+        if not verts:
+            verts = np.array([[], []]).T
+
         return verts, codes

     def get_glyphs_with_font(self, font, s, glyph_map=None,

Writing a test by isolating the call to text2path for this proved to be the difficult part and I didn't quite get that far.

@tacaswell
Copy link
Member

Closing this because this seems like same underlying issue as #2698 @pelson @saullocastro Re-open if you disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants