Negative numbers are not displayed correctly in matplotlib xkcd style
I have been playing around with the xkcd style function 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 sample code, I get a "?" instead of "-" labels must be negative at all times. Any idea what is causing this?
with plt.xkcd():
plt.figure()
plt.plot(np.sin(np.linspace(0, 10)))
plt.title('Whoo Hoo!!!')
Edit: In Bernie's suggestion (thanks Bernie) I tried several different sides. Tried Qt, Tkinter and inline and none seem to work. I am using Ipython 2.3 btw.
Also, the reputation is now high enough to post an image. As you can see, everything is as expected except for those annoying question marks.
source to share
Eryksun's comment is right. So you have to add MINUS SIGN (U + 2212) character to xkcd (hunour sans) font. To do this, use a font editor (I used FontForge ):
- From the FontForge menu open the juniors file Sans ttf.
- Copy the glyph HYPHEN-MINUS (U + 002d) into the MINUS SIGN (U + 2212) character field (they are in ascending order of Unicode number).
- Go to File -> Create Font. Select True Type (.ttf) and save it in a folder other than the Fonts folder.
- Install the new saved font. (on Windows, double-click to open the preview window, then click Install).
I had the same problem as you and this solved it.
source to share