|
From: Fernando P. <Fer...@co...> - 2006-01-21 15:32:21
|
Hi all, I'm wondering if it's really possible to use other latex font packages. I just updated to CVS mpl, dvipng 1.7 and ghostscript 8.50-gpl to make sure I was fully current. My tex-related settings are: text.usetex : True text.tex.engine : latex And yet, I can set: font.latex.package : foobar or anything in 'foobar', and there is absolutely no change in the resulting plots. My goal is to be able to use the latex helvetica fonts, but setting this to 'helvetica', doesn't work. I've also tried 'times', 'pslatex' and other valid latex packages, to no avail (meaning, titles and labels continue using ComputerModern fonts). Basically my question is: does the font.latex.package setting actually do _anything_? Or am I using it incorrectly? Any help appreciated... f |
|
From: John H. <jdh...@ac...> - 2006-01-21 16:49:07
|
>>>>> "Fernando" == Fernando Perez <Fer...@co...> writes:
Fernando> Basically my question is: does the font.latex.package
Fernando> setting actually do _anything_? Or am I using it
Fernando> incorrectly?
Try flushine the cache ~/.matplotlib/tex.cache/
I didn't look, but we may not be including the latex header in the
font caching hash string.
JDH
|
|
From: Fernando P. <Fer...@co...> - 2006-01-21 16:52:51
|
John Hunter wrote: >>>>>>"Fernando" == Fernando Perez <Fer...@co...> writes: > > > Fernando> Basically my question is: does the font.latex.package > Fernando> setting actually do _anything_? Or am I using it > Fernando> incorrectly? > > Try flushine the cache ~/.matplotlib/tex.cache/ That did it, thanks. Is this a one-off thing because I had stale info there? Or does it need to be done every time you change your latex font package selection? If the latter, I guess it should be considered a bug. Cheers, f |
|
From: Darren D. <dd...@co...> - 2006-01-21 18:23:10
|
On Saturday 21 January 2006 11:52 am, Fernando Perez wrote: > John Hunter wrote: > >>>>>>"Fernando" == Fernando Perez <Fer...@co...> writes: > > > > Fernando> Basically my question is: does the font.latex.package > > Fernando> setting actually do _anything_? Or am I using it > > Fernando> incorrectly? > > > > Try flushine the cache ~/.matplotlib/tex.cache/ > > That did it, thanks. Is this a one-off thing because I had stale info > there? Or does it need to be done every time you change your latex font > package selection? If the latter, I guess it should be considered a bug. It's a bug. We need to either include the font information in the md5 ().hexdigest, or we need to add font directories under tex.cache to keep things separate. I dont know what is the right way to do it, now that there is low-level font command support in mpl (I'm not familiar with that part of the code and unfortunately dont have time to familiarize myself with it this week). Darren |
|
From: John H. <jdh...@ac...> - 2006-01-21 18:37:43
|
>>>>> "Darren" == Darren Dale <dd...@co...> writes:
Darren> It's a bug. We need to either include the font information
Darren> in the md5 ().hexdigest, or we need to add font
I just committed a change to include the rc font info in the hash
name. This will obviate the old cache, so feel free to flush it.
Thanks,
JDH
|
|
From: Fernando P. <Fer...@co...> - 2006-01-22 00:14:16
|
John Hunter wrote:
>>>>>>"Darren" == Darren Dale <dd...@co...> writes:
>
> Darren> It's a bug. We need to either include the font information
> Darren> in the md5 ().hexdigest, or we need to add font
>
> I just committed a change to include the rc font info in the hash
> name. This will obviate the old cache, so feel free to flush it.
OK, I'm still seeing very funny behavior (current mpl form CVS). Let me try
to document things as I go, so you have a record. I have permanently set:
text.usetex : True
text.tex.engine : latex
ps.useafm : False
mp is a macro which does:
In [23]: p mp.value
figure()
plot([1,2,3])
title(r'Hello matplotlib: $x=1+\alpha')
Running it any number of times, all the while changing this:
In [28]: rc('font.latex',package='times')
to 'times', 'helvetica', etc, produces no change in the generated picture. Is
this setting supposed to be ignored? I see that
http://www.scipy.org/wikis/topical_software/UsingTex
mentions that these parameters can be changed 'before importing pylab'. Any
reason why they can't be reset on the fly?
I can see that it IS possible to get either helvetica or CM. But it seems
like I HAVE to make the choice at startup time, in my matplotlibrc file. And
it only seems to work by setting If I set:
font.family : serif (or sans-)
AND
blowing away the font-cache on each pylab restart.
Trying to switch back and forth between modes doesn't seem to work unless you
blow the cache (even restarting pylab), so something is still broken re. cache
handling.
AND, even worse, I'm getting consistently that if I select
font.latex.package : helvetica
produces a nasty error (I can send the full tb if needed):
/usr/lib/python2.3/site-packages/matplotlib/backends/backend_agg.py in
get_text_width_height(self, s, prop, ismath, rgb)
241 size = prop.get_size_in_points()
242 dpi = self.dpi.get()
--> 243 Z = self.texmanager.get_rgba(s, size, dpi, rgb)
244 m,n,tmp = Z.shape
245 return n,m
/usr/lib/python2.3/site-packages/matplotlib/texmanager.py in get_rgba(self,
tex, fontsize, dpi, rgb)
310 # force=True to skip cacheing while debugging
311 pngfile = self.make_png(tex, dpi, force=False)
--> 312 X = readpng(pngfile)
313 vers = self.get_dvipng_version()
314 #print 'dvipng version', vers
RuntimeError: _image_module::readpng could not open PNG file
/home/fperez/.matplotlib/tex.cache/4c6661ae3b1f9211424cf72e05973891_120.png
for reading
So the latex.package part seems broken.
Cheers,
f
ps - John, you really should, in the users_guide.tex,
\usepackage{hyperref}
so the PDF has internal links. This makes a big convenience difference for
the use of the table of contents. The fancy form (intended for compilation
with pdflatex, NOT latex), [this is from common_preamble.tex in the p20 doc]:
% This gives us a better font in URL links (otherwise the default
% MonoSpace font is bitmapped, and it looks horrible in PDF)
\usepackage{courier}
\usepackage{color}
% The hyperref package gives us a pdf with properly built
% internal navigation ('pdf bookmarks' for the table of contents,
% internal cross-reference links, web links for URLs, etc.)
% A few colors to replace the defaults for certain link types
\definecolor{darkorange}{rgb}{.71,0.21,0.01}
\definecolor{darkgreen}{rgb}{.12,.54,.11}
\usepackage[pdftex, % needed for pdflatex
breaklinks=true, % so long urls are correctly broken across lines
colorlinks=true,
urlcolor=blue,
linkcolor=darkorange,
citecolor=darkgreen,
]{hyperref}
% This helps prevent overly long lines that stretch beyond the margins
\sloppy
|
|
From: John H. <jdh...@ac...> - 2006-01-22 13:31:13
|
>>>>> "Fernando" == Fernando Perez <Fer...@co...> writes:
Fernando> In [23]: p mp.value figure() plot([1,2,3]) title(r'Hello
Fernando> matplotlib: $x=1+\alpha')
I assume you have another dollar sign in there in real life?
Fernando> Running it any number of times, all the while changing
Fernando> this:
Fernando> In [28]: rc('font.latex',package='times')
Fernando> to 'times', 'helvetica', etc, produces no change in the
Fernando> generated picture. Is this setting supposed to be
Fernando> ignored? I see that
Fernando> http://www.scipy.org/wikis/topical_software/UsingTex
Fernando> mentions that these parameters can be changed 'before
Fernando> importing pylab'. Any reason why they can't be reset on
Fernando> the fly?
No, you should be able to change them on the fly. It turns out that
agg is also doing some caching of the generated images, and this is
where the problem was (there was also one in texmanager that I fixed
yesterday). I just committed some changes that are untested but
should work. FYI, the relevant bits of the code are texmanager's
get_prefix and backend_agg's draw_tex functions. Previously in agg I
was caching on
key = s, size, dpi, rgb, angle
and I added the rc info to the key
key = s, size, dpi, rgb, angle, rcParams['font.latex'],rcParams['text.tex.engine']
Fernando> AND, even worse, I'm getting consistently that if I
Fernando> select
Fernando> font.latex.package : helvetica
Fernando> produces a nasty error (I can send the full tb if
Fernando> needed):
Fernando> RuntimeError: _image_module::readpng could not open PNG
Fernando> file
Fernando> /home/fperez/.matplotlib/tex.cache/4c6661ae3b1f9211424cf72e05973891_120.png
Fernando> for reading
Flush the cache and reinstall from CVS and make sure you can repeat
this error after the newest fixes (probably still there but worth a
try). If so inspect the pointed to PNG file and see what is going on
with it: does it exist, does it have data in it, is it in fact a
readable png?
Cheers,
JDH
|
|
From: Darren D. <dd...@co...> - 2006-01-22 17:16:48
|
On Saturday 21 January 2006 7:14 pm, Fernando Perez wrote: > AND, even worse, I'm getting consistently that if I select > > font.latex.package : helvetica > > produces a nasty error (I can send the full tb if needed): [...] > RuntimeError: _image_module::readpng could not open PNG file > /home/fperez/.matplotlib/tex.cache/4c6661ae3b1f9211424cf72e05973891_120.png > for reading Oh, helvetica is not a valid package, so latex fails and dvipng is unable to produce the png file. I think you are looking for the "helvet" package. I should go through texmf/tex/latex/ and make a list of all the valid font packages for latex, and include the list in the rc file. Darren |
|
From: Fernando P. <Fer...@co...> - 2006-01-22 19:59:02
|
Darren Dale wrote: > On Saturday 21 January 2006 7:14 pm, Fernando Perez wrote: > >>AND, even worse, I'm getting consistently that if I select >> >>font.latex.package : helvetica >> >>produces a nasty error (I can send the full tb if needed): > > [...] > >>RuntimeError: _image_module::readpng could not open PNG file >>/home/fperez/.matplotlib/tex.cache/4c6661ae3b1f9211424cf72e05973891_120.png >>for reading > > > > Oh, helvetica is not a valid package, so latex fails and dvipng is unable to > produce the png file. I think you are looking for the "helvet" package. I > should go through texmf/tex/latex/ and make a list of all the valid font > packages for latex, and include the list in the rc file. Ah, sorry, my fault then! Yes, listing the correct latex font package names in the rc file would be good, I was going on memory and typed the wrong one. Many thanks for your efforts on this problem: I won't be able to look at this today, but I will again soon. Regards, f |
|
From: Darren D. <dd...@co...> - 2006-01-22 17:02:53
|
On Sunday 22 January 2006 8:21 am, John Hunter wrote: > Flush the cache and reinstall from CVS and make sure you can repeat > this error after the newest fixes (probably still there but worth a > try). If so inspect the pointed to PNG file and see what is going on > with it: does it exist, does it have data in it, is it in fact a > readable png? I fixed a bad rcParams key in backend_agg (fixed in cvs), but I still cant change the fonts on the fly. That got me thinking, isn't it the case that any rcParams need to be changed before importing from pylab, or has this requirement changed? John's changes do work if you make rc changes before importing from pylab. Darren |
|
From: John H. <jdh...@ac...> - 2006-01-22 17:25:20
|
>>>>> "Darren" == Darren Dale <dd...@co...> writes:
Darren> I fixed a bad rcParams key in backend_agg (fixed in cvs),
Darren> but I still cant change the fonts on the fly. That got me
Darren> thinking, isn't it the case that any rcParams need to be
Darren> changed before importing from pylab, or has this
Darren> requirement changed? John's changes do work if you make rc
Darren> changes before importing from pylab.
rcParams is just a dict, so you can modify it and have the changes
work w/o restarting pylab. As long as the dict is being read in a
function (and not at the module import level) then you should have no
trouble changing rc on the fly as long as we get the cache keys right.
I think the changes I made to backend agg should work, but testing
will be the final arbiter. Are you seeing problems with CVS chcked
out today?
JDH
|
|
From: Darren D. <dd...@co...> - 2006-01-22 17:38:40
|
On Sunday 22 January 2006 12:15 pm, you wrote:
> >>>>> "Darren" == Darren Dale <dd...@co...> writes:
>
> Darren> I fixed a bad rcParams key in backend_agg (fixed in cvs),
> Darren> but I still cant change the fonts on the fly. That got me
> Darren> thinking, isn't it the case that any rcParams need to be
> Darren> changed before importing from pylab, or has this
> Darren> requirement changed? John's changes do work if you make rc
> Darren> changes before importing from pylab.
>
> rcParams is just a dict, so you can modify it and have the changes
> work w/o restarting pylab. As long as the dict is being read in a
> function (and not at the module import level) then you should have no
> trouble changing rc on the fly as long as we get the cache keys right.
>
> I think the changes I made to backend agg should work, but testing
> will be the final arbiter. Are you seeing problems with CVS chcked
> out today?
in ipython -pylab, I tried something along the lines of:
from matplotlib import rcParams
# pslatex is my default latex font package
figure()
title(r'hello matplotlib: $x=e^{i\pi\theta}$')
savefig('pslatex.eps')
rcParams['font.latex.package']='type1cm'
figure()
title(r'hello matplotlib: $x=e^{i\pi\theta}$')
savefig('type1cm.eps')
Both of these figures look the same on screen, but type1cm is used in the
epsfile. Does backend_agg read the rcParams dict during module import only?
That might explain this behavior...
Darren
|
|
From: John H. <jdh...@ac...> - 2006-01-22 18:24:16
|
>>>>> "GDarren" == Darren Dale <dd...@co...> writes:
GDarren> Both of these figures look the same on screen, but
GDarren> type1cm is used in the epsfile. Does backend_agg read the
GDarren> rcParams dict during module import only? That might
GDarren> explain this behavior...
No, it reads it in the function draw_tex. With the changes you made
in backend_agg it should work. Did you flush your cache after making
these changes and reinstalling.
When in doubt, insert some print statements in draw_tex to make sure
what you think should be happening is happening.
Confused in Chicago,
JDH
|