First time here? Check out the FAQ!

Ask Your Question
1

xkcd and matplotlib

asked 10 years ago

JoalHeagney gravatar image

updated 10 years ago

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 10 years ago

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.

Preview: (hide)
link
2

answered 10 years ago

Antlab gravatar image

updated 10 years ago

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.

Preview: (hide)
link

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 ( 10 years ago )

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: 10 years ago

Seen: 3,183 times

Last updated: May 21 '14