[Pythonmac-SIG] matplotlib and postscript output

Teemu Rinne teemu.rinne at helsinki.fi
Fri Sep 9 08:24:18 CEST 2005


Thanks a lot! I am now able to create ps output and can proceed with my 
work (although I have to deal with the fonts manually, but that's better 
than no postscript at all).

Yes, the problem has something to do with fonts.

My test script is now like this:

#pstest.py
import matplotlib
matplotlib.use('Agg')
import pylab

from matplotlib import rc
rc('font',  family='serif', style='normal', variant='normal',
   weight='bold',  stretch='normal', size='small')

pylab.plot(pylab.arange(5),pylab.arange(5),'k-')
pylab.title("some title")
pylab.xlabel('some unit label')
pylab.ylabel('some different unit label')

pylab.savefig("filename.ps")


I tried setting different fonts in my .matplotrc.
For example with Times:

font.serif          : Times


python pstest.py --verbose-debug
matplotlib data path 
/System/Library/Frameworks/Python.framework/Versions/2.3/share/matplotlib
loaded rc file /Users/teemu/.matplotlibrc
matplotlib version 0.80
verbose.level debug
interactive is False
platform is darwin
loaded modules: ['__future__', 'copy_reg', 'sre_compile', 'distutils', 
'_sre', '__main__', 'site', '__builtin__', 'datetime', 'encodings', 
'encodings.encodings', 'sre_constants', 'distutils.string', 
'matplotlib.datetime', 'posixpath', 'matplotlib.warnings', 
'encodings.codecs', 'matplotlib.sys', 're', 'os.path', '_codecs', 
'distutils.sysconfig', 'encodings.exceptions', 'stat', 'zipimport', 
'string', 'warnings', 'encodings.types', 'UserDict', 'encodings.ascii', 
'distutils.os', 'matplotlib', 'sys', 'matplotlib.__future__', 'codecs', 
'distutils.re', 'types', 'strop', 'matplotlib.os', 'sre', 
'matplotlib.distutils', 'signal', 'distutils.errors', 'linecache', 'posix', 
'encodings.aliases', 'exceptions', 'sre_parse', 'distutils.sys', 'os']
numerix Numeric 23.8
font search path 
['/System/Library/Frameworks/Python.framework/Versions/2.3/share/matplotlib']
trying fontname 
/System/Library/Frameworks/Python.framework/Versions/2.3/share/matplotlib/VeraMoBI.ttf
trying fontname 
/System/Library/Frameworks/Python.framework/Versions/2.3/share/matplotlib/VeraMoIt.ttf
trying fontname 
/System/Library/Frameworks/Python.framework/Versions/2.3/share/matplotlib/cmtt10.ttf
trying fontname 
/System/Library/Frameworks/Python.framework/Versions/2.3/share/matplotlib/VeraSe.ttf
trying fontname 
/System/Library/Frameworks/Python.framework/Versions/2.3/share/matplotlib/VeraBI.ttf
trying fontname 
/System/Library/Frameworks/Python.framework/Versions/2.3/share/matplotlib/Vera.ttf
loaded ttfcache file /Users/tjrinne/.ttffont.cache
backend Agg version v2.2
        findfont found Times, normal, normal 700, normal, 10.0
findfont returning /System/Library/Fonts/Times.dfont
        findfont found Times, normal, normal 700, normal, 12.0
findfont returning /System/Library/Fonts/Times.dfont
        findfont found Times, normal, normal 700, normal, 14.0
findfont returning /System/Library/Fonts/Times.dfont
        findfont cached Times, normal, normal, 700, normal, 10.0
findfont returning /System/Library/Fonts/Times.dfont
        findfont cached Times, normal, normal, 700, normal, 12.0
findfont returning /System/Library/Fonts/Times.dfont
        findfont cached Times, normal, normal, 700, normal, 14.0
findfont returning /System/Library/Fonts/Times.dfont

Everything looks ok to me but the result is a broken 3.2 M file.


With palatino

font.serif          : Palatino

I get a 12 K file which cannot be opened.


Postscript output works with

font.serif          :

(i.e., empty)
which makes matplotlib to use Vera.


So far it seems that only the Vera font works and all the system fonts 
result in a broken postscript file.

There seems to be no such font problems on my US powerbook but all my 
international (Finnish keyboards) macs (2 out-of-box Tigers, one older 
Panther) show it. Although all my Finnish macs behave like this, nobody on 
this list seems to have similar problems. Could the font problem be somehow 
specific to international (or even Finnish) macs?


--
Teemu


--On torstai 8. syyskuu 2005 22:57 -0500 John Hunter 
<jdhunter at nitace.bsd.uchicago.edu> wrote:

>>>>>> "Teemu" == Teemu Rinne <Teemu.Rinne at helsinki.fi> writes:
>
>     Teemu> Any help/suggestions would be greatly appreciated.
>
> matplotlib emes it's freetype fonts into the postscript file.  The
> fonts it finds are usually platform and per-computer specific.  It
> looks to me like the errant platform has some extremely large,
> possibly corrupt fonts that are getting dumped into your PS file.
>
> Try running with
>
>> python myscript.py --verbose-debug
>
> which will print lots of extra debug info including which font files
> are used.  My guess is if you move the problematic fonts out of your
> font search path the problem will go away.
>
> JDH




More information about the Pythonmac-SIG mailing list