Ask Your Question
1

xkcd and matplotlib

asked 2014-05-13 05:56:43 +0100

JoalHeagney gravatar image

updated 2014-05-21 03:17:31 +0100

Hi guys. Attempting to use the xkcd graphics feature that has been recently added to matplotlib from within sagemath.

import matplotlib.pyplot
matplotlib.pyplot.xkcd()
plot(sin(x),(x,-pi,pi),ticks=pi/4,tick_formatter=pi)

Matplotlib throws the following warning:

/home/joal/bin/sage-6.2/local/lib/python2.7/site-packages/matplotlib-1.3\ .1-py2.7-linux-x86_64.egg/matplotlib/font_manager.py:1236: UserWarning: findfont: Font family ['Humor Sans', 'Comic Sans MS'] not found. Falling back to Bitstream Vera Sans (prop.get_family(), self.defaultFamily[fontext]))

I have installed Humor Sans.ttf onto the main system, and into the directory:
/home/joal/bin/sage-6.2/local/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/mpl-data/fonts/

... but don't know how to reset the matplotlib font cache so matplotlib will pay attention to the new font.


[EDIT]

Okay, seem to have part of the solution - need to verify on a Linux machine this weekend.

EDIT of EDIT
The tricks below don't work on LinuxMint.

The font is recognised in the virtualbox image if it is dumped into:
sage-6.2/local/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/mpl-data/fonts/
and renamed Humor-Sans.ttf

Then you need to create a .matplotlib folder in the user directory.
mkdir ~/.matplotlib

The concern is that it now that Humor Sans is used for text font, but not for the numbers on the horizontal and vertical axes. Any suggestions, sagers?


[EDIT]

Which turns out to be a consequence of using the pi tick_formatter.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-05-21 03:31:50 +0100

JoalHeagney gravatar image

Okay, finally have most of an answer.

  1. Install Humor-Sans.ttf in ~/.fonts (You may have to rename it).
  2. Under Linux, the .matplotlib directory lives in ~/.sage. cd into it and remove the fontList.cache

  3. Currently, use of constant-value tick_formatters such as pi, e, sqrt(2) will default back to using the normal font - this is unlikely to have a quick solution as the Humor Sans font is missing several mathematical symbols any way.

edit flag offensive delete link more
2

answered 2014-05-13 09:57:04 +0100

Antlab gravatar image

updated 2014-05-13 09:57:23 +0100

Hi. It seems that other people had that problem with the xkcd font in matplotlib. Here there is an interesting post concerning hte issue:

http://raj.blog.archive.org/tag/matpl...

In your case probably you only need to rebuild the cache with the command:

$ rm ~/.matplotlib/fontList.cache

Hope this helps.

edit flag offensive delete link more

Comments

Hi Antlab. Yup, that's the issue that I found. The problem is that I can't find the .matplotlib on my Linux install, either in the home directory, or in the sage directory.

JoalHeagney gravatar imageJoalHeagney ( 2014-05-19 20:09:40 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-05-13 05:56:43 +0100

Seen: 3,104 times

Last updated: May 21 '14