Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Negative numbers don't display correctly in matplotlib xkcd style

I've been playing with the xkcd style feature in matplotlib. I have Matplotlib 1.4, and the humor sans font is installed correctly, or works in msword at least.

When I run the following example code, I get "?" instead of "-" on labels any time there should be a negative number. Any idea what causes this?

with plt.xkcd():
  plt.figure()
  plt.plot(np.sin(np.linspace(0, 10)))
  plt.title('Whoo Hoo!!!')

enter image description here

Edit: At Bernie's suggestion (thanks Bernie) I tried some different backends. Tried Qt, Tkinter, and inline, and none seem to work. I'm using Ipython 2.3 btw.

Also, reputation is now high enough to post an image. As you can see everything is as expected except those pesky question marks.

like image 372
Nathan Kiner Avatar asked Oct 31 '22 16:10

Nathan Kiner


1 Answers

eryksun comment is right. Thus, you must add the MINUS SIGN (U+2212) character to the xkcd font (hunour sans). To do so, use a font editor (I used FontForge):

  1. From the FontForge menu, open the Humour Sans ttf file.
  2. Copy paste the HYPHEN-MINUS (U+002d) glyph to the MINUS SIGN (U+2212) character box (they are ordered in increasing Unicode number).
  3. Go to File -> Generate Font. Choose True Type (.ttf) and save it in a different folder than your Fonts folder.
  4. Install the newly saved Font. (on Windows, double click to open a preview window, then click install)

I had the same problem as you and that solved it.

like image 85
Ludo Avatar answered Nov 05 '22 02:11

Ludo