ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 20 May 2014 20:31:50 -0500xkcd and matplotlibhttps://ask.sagemath.org/question/11366/xkcd-and-matplotlib/<p>Hi guys. Attempting to use the xkcd graphics feature that has been recently added to matplotlib from within sagemath.</p>
<p>import matplotlib.pyplot<br>
matplotlib.pyplot.xkcd()<br>
plot(sin(x),(x,-pi,pi),ticks=pi/4,tick_formatter=pi)</p>
<p>Matplotlib throws the following warning: </p>
<p><i>/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></p>
I have installed Humor Sans.ttf onto the main system, and into the directory: <br>
<i>/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/</i>
... but don't know how to reset the matplotlib font cache so matplotlib will pay attention to the new font.
----------
[EDIT]
<p>Okay, seem to have part of the solution - need to verify on a Linux machine this weekend.</p>
<p>EDIT of EDIT<br>
The tricks below don't work on LinuxMint.</p>
<p>The font is recognised in the virtualbox image if it is dumped into:<br>
<i>sage-6.2/local/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/mpl-data/fonts/</i><br>
and renamed <i>Humor-Sans.ttf</i></p>
<p>Then you need to create a .matplotlib folder in the user directory.<br>
<i>mkdir ~/.matplotlib</i></p>
<p>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?</p>
----------
[EDIT]
<p>Which turns out to be a consequence of using the pi tick_formatter.</p>Mon, 12 May 2014 22:56:43 -0500https://ask.sagemath.org/question/11366/xkcd-and-matplotlib/Answer by JoalHeagney for <p>Hi guys. Attempting to use the xkcd graphics feature that has been recently added to matplotlib from within sagemath.</p>
<p>import matplotlib.pyplot<br/>
matplotlib.pyplot.xkcd()<br/>
plot(sin(x),(x,-pi,pi),ticks=pi/4,tick_formatter=pi)</p>
<p>Matplotlib throws the following warning: </p>
<p><i>/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></p>
<p>I have installed Humor Sans.ttf onto the main system, and into the directory: <br/>
<i>/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/</i></p>
<p>... but don't know how to reset the matplotlib font cache so matplotlib will pay attention to the new font. </p>
<hr/>
<p>[EDIT]</p>
<p>Okay, seem to have part of the solution - need to verify on a Linux machine this weekend.</p>
<p>EDIT of EDIT<br/>
The tricks below don't work on LinuxMint.</p>
<p>The font is recognised in the virtualbox image if it is dumped into:<br/>
<i>sage-6.2/local/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/mpl-data/fonts/</i><br/>
and renamed <i>Humor-Sans.ttf</i></p>
<p>Then you need to create a .matplotlib folder in the user directory.<br/>
<i>mkdir ~/.matplotlib</i></p>
<p>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?</p>
<hr/>
<p>[EDIT] </p>
<p>Which turns out to be a consequence of using the pi tick_formatter.</p>
https://ask.sagemath.org/question/11366/xkcd-and-matplotlib/?answer=16130#post-id-16130Okay, 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.Tue, 20 May 2014 20:31:50 -0500https://ask.sagemath.org/question/11366/xkcd-and-matplotlib/?answer=16130#post-id-16130Answer by Antlab for <p>Hi guys. Attempting to use the xkcd graphics feature that has been recently added to matplotlib from within sagemath.</p>
<p>import matplotlib.pyplot<br/>
matplotlib.pyplot.xkcd()<br/>
plot(sin(x),(x,-pi,pi),ticks=pi/4,tick_formatter=pi)</p>
<p>Matplotlib throws the following warning: </p>
<p><i>/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></p>
<p>I have installed Humor Sans.ttf onto the main system, and into the directory: <br/>
<i>/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/</i></p>
<p>... but don't know how to reset the matplotlib font cache so matplotlib will pay attention to the new font. </p>
<hr/>
<p>[EDIT]</p>
<p>Okay, seem to have part of the solution - need to verify on a Linux machine this weekend.</p>
<p>EDIT of EDIT<br/>
The tricks below don't work on LinuxMint.</p>
<p>The font is recognised in the virtualbox image if it is dumped into:<br/>
<i>sage-6.2/local/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/mpl-data/fonts/</i><br/>
and renamed <i>Humor-Sans.ttf</i></p>
<p>Then you need to create a .matplotlib folder in the user directory.<br/>
<i>mkdir ~/.matplotlib</i></p>
<p>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?</p>
<hr/>
<p>[EDIT] </p>
<p>Which turns out to be a consequence of using the pi tick_formatter.</p>
https://ask.sagemath.org/question/11366/xkcd-and-matplotlib/?answer=16129#post-id-16129Hi.
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/matplotlib/
In your case probably you only need to rebuild the cache with the command:
$ rm ~/.matplotlib/fontList.cache
Hope this helps.Tue, 13 May 2014 02:57:04 -0500https://ask.sagemath.org/question/11366/xkcd-and-matplotlib/?answer=16129#post-id-16129Comment by JoalHeagney for <p>Hi.
It seems that other people had that problem with the xkcd font in matplotlib.
Here there is an interesting post concerning hte issue:</p>
<p><a href="http://raj.blog.archive.org/tag/matplotlib/">http://raj.blog.archive.org/tag/matpl...</a></p>
<p>In your case probably you only need to rebuild the cache with the command:</p>
<p>$ rm ~/.matplotlib/fontList.cache</p>
<p>Hope this helps.</p>
https://ask.sagemath.org/question/11366/xkcd-and-matplotlib/?comment=16170#post-id-16170Hi 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.Mon, 19 May 2014 13:09:40 -0500https://ask.sagemath.org/question/11366/xkcd-and-matplotlib/?comment=16170#post-id-16170