From: George N. <ag...@no...> - 2005-05-22 22:01:11
|
Thought I'd summarize my experiences. They may result from a messed up =20= installation, but could be useful for others -- Bradley Minch, using =20 10.2.8, seems to have had my initial problem, #I below. Excuse the overlong email here. Many thanks to Darren Dale for helping me out. Setup: matplotlib 0.80, ipython 0.6.13, readline.so [from =20 www.pycs.net/bbum/2004/1/21/readline.so.gz] zlib, libpng, tk_inter8.4, freetype 2.1.9 [produces =20 libfreetype.6.3.7.dylib], wx-2.6-mac-unicode, standard Panther Apple Python 2.3, updated to MacPython, scipy 0.3.2 [from =20 http://cbis.anu.edu.au/misc/SciPy_complete-0.3.2.mpkg.zip] Numeric 23.1, OS X 10.3.9 Running with TkAgg backend set in .matplotlibrc 1. Original problem: First time I did from pylab import * (or ipython -pylab) got error while font_manager was trying to build the ttffont.cache... =C2=A0 File =20 "/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-=20= packages/matplotlib/font_manager.py", line 347, in ttfFontProperty =C2=A0=C2=A0=C2=A0 size =3D str(float(font.get_fontsize())) AttributeError: get_fontsize Now, when building the ttf cache, font_manager searches for TrueType =20 fonts. 1. in the matplotlib data directory =20 /System/Library/Frameworks/Python.framework/Versions/2.3/share/=20 matplotlib 2. In the normal Mac places /Library/Fonts/, /System/Library/Fonts,/Network/Library/Fonts, =20 ~/Library/Fonts Tracked this problem down to the font VT102Font that I had in =20 ~/Library/Fonts. Moved VT102Font to (new directory) ~/SuspectFonts off the font path. Problem 1 solved! from pylab import * now happily built a =20 ~/.ttffont.cache for me. 2. Next problem -- absurdly large, corrupted, PS files. Ran this script that produces simple plots, with axes labelled (by =20 default) with sans-serif numbers. dt =3D 0.01 t =3D arange(0,10,dt) subplot(211) s =3D sin(t) plot(t,s) subplot(212) c =3D cos(t) plot(t,c) savefig('/Users/agn/sincos.png') -- produced a nice file ~28KB in size savefig('/Users/agn/sincos.ps') -- produced a file of 4.6MB. Trying to view this file using Apple preview, or converting it to pdf =20= with ps2pdf (ps2pdf13, v1.3, 21Feb2002) or Apple pstopdf gave an error. =20= E.g. ps2pdf sincos.ps gave: Error: /invalidfont in -dict- Operand stack: LucidaGrande --dict:10/14(L)-- Font LucidaGrande =20 --dict:10/14(L)-- LucidaGrande Darren Dale sorted me out here. The default sans-serif font used to =20 label the axes is the first font in the san-serif line (about line 113) =20= in the .matplotlibrc startup file. The default .matplotlibrc gives =20 LucidaGrande as that default font. LucidaGrande.dfont is an Apple =20 standard font living in /System/Library/Fonts. He suggested that I put Bitstream Vera Sans as the first font on the =20= san-serif line in .matplotlibrc, so that this font, which comes with =20 matplotlib, and lives in =20 /System/Library/Frameworks/Python.framework/Versions/2.3/share/=20 matplotlib is used as the default sans-serif font instead. Problem 2 solved. savefig('/Users/agn/sincos.ps') now gives a 176 KB =20 ps, that reduces to a 36KB pdf. Perfectly OK now. Suspected same problem would arise for other families, so put Bitstream =20= Vera Serif as the default serif font, & Bitstream Vera Sans Mono as =20 the default monospace font. 3. John Hunter suggested that problem 2 might be solved if I were to =20 modify line 180 of .matplotlibrc to set ps.useafm : True This should give smaller Ps files at the cost of breaking mathtext =20 (which incidentally *does* (almost completely) work for me with =20 ps.useafm : False). Unfortunately, setting ps.useafm true doesn't work for me. Now if =20 ps.useafm is True, font_manager only makes a cache -- .afmfont.cache =20= -- when you first try to save to PS. I have at present the problem that =20= font_manager is falling over when trying to make this cache. One of the =20= Chinese-type opentype (.otf) fonts --- = /System/Library/Fonts/=E3=83=92=E3=83=A9=E3=82=AD=E3=82=99=E3=83=8E=E6=98=8E= =E6=9C=9D =20 Pro W3.otf -- or in hex /System/Library/Fonts/=20 \xe3\x83\x92\xe3\x83\xa9\xe3\x82\xad\xe3\x82\x99\xe3\x83\x8e\xe6\x98\x8e=20= \xe6\x9c\x9d Pro W3.otf causes an infinite loop with 'Key error converting in AFM' in afm.py, =20= when trying to parse the header. Quite a few fonts are in 'seen', -- {'pbkd8a.afm': 1, 'pagd8a.afm': 1, 'pbkl8a.afm': 1, 'ptmri8a.afm': 1, =20= 'pncb8a.afm': 1, 'phvbo8a.afm': 1, 'phvb8an.afm': 1, 'phvro8an.afm': 1, =20= 'ptmb8a.afm': 1, 'pcrro8a.afm': 1, 'pcrb8a.afm': 1, 'pplr8a.afm': 1, =20 'pzdr.afm': 1, 'cmsy10.afm': 1, 'phvlo8a.afm': 1, 'cmr10.afm': 1, =20 'phvb8a.afm': 1, 'phvl8a.afm': 1, 'pncri8a.afm': 1, 'pagdo8a.afm': 1, =20= 'putri8a.afm': 1, 'pzcmi8a.afm': 1, 'ptmbi8a.afm': 1, 'phvro8a.afm': 1, =20= 'putr8a.afm': 1, 'phvbo8an.afm': 1, 'pcrr8a.afm': 1, 'putbi8a.afm': 1, =20= 'pcrbo8a.afm': 1, 'cmtt10.afm': 1, 'pplb8a.afm': 1, 'pbkdi8a.afm': 1, =20= 'pagk8a.afm': 1, 'pncr8a.afm': 1, 'putb8a.afm': 1, 'psyr.afm': 1, =20 'pagko8a.afm': 1, 'pplbi8a.afm': 1, 'pbkli8a.afm': 1, 'pncbi8a.afm': 1, =20= 'cmmi10.afm': 1, 'ptmr8a.afm': 1, 'pplri8a.afm': 1, 'cmex10.afm': 1, =20 'phvr8a.afm': 1, =20 '\xe3\x83\x92\xe3\x83\xa9\xe3\x82\xad\xe3\x82\x99\xe3\x83\x8e\xe6\x98\x8=20= e\xe6\x9c\x9d Pro W3.otf': 1, 'phvr8an.afm': 1} so have presumably been successfully parsed, except for this .otf font. Haven't sorted this problem out yet. I suppose I could try removing the =20= East Asian fonts from the system folder, or changing font_manager so it =20= does not read them in. 4. Conclusion: For me, the only fonts that work are the BitStream Vera =20= Fonts supplied with matplotlib. Not ideal, because they do do not =20 include italic, cursive, or fantasy fonts (although they do include an =20= *oblique* sans serif font). But this is sufficient to make matplotlib =20= work for most practical purposes, especially as mathtext does work =20 (though ps2pdf can't convert the ps fonts to pdf; Apple pstopdf (used =20= by Preview) must be used) Again, many thanks to Darren Dale and also to John Hunter and Fernando =20= Perez for their replies. George Nurser. |