Ask Your Question

xkcd and matplotlib

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

JoalHeagney gravatar image

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

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

import matplotlib.pyplot

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/ 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:

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


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

The tricks below don't work on LinuxMint.

The font is recognised in the virtualbox image if it is dumped into:
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?


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

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

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

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

Antlab gravatar image

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

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

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


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 +0200 )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


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

Seen: 2,878 times

Last updated: May 21 '14