Problem changing font properties

Running OS X 10.3.9 matplotlib 0.87.2
If I run:

import matplotlib
matplotlib.use('PS')
from matplotlib import pylab
import Numeric
N = Numeric
PL = pylab
x = N.arrayrange(100.)
y = N.arrayrange(100.)
PL.plot(x,y**2)
PL.savefig('crap')
PL.clf()

with the default matplotlibrc setting:
font.sans-serif : Lucida Grande, Verdana, Geneva, Lucida, Bitstream Vera Sans, Arial, Helvetica, Avant Garde, sans-serif
I get a postscript file that I cannot view.
BUT if I change the matplotlibrc file to:
font.sans-serif : Bitstream Vera Sans
All goes well and the PS file is fine. This has been discussed on the list previously as an OS X font issue.

My idea was to use the following code to set the font.sans-serif dynamically.
However, it does not seem to work in that the ps file is not usable as if Lucida Grande was still the font.sans-serif setting.
There might well be something very obvious - From the font manager code I surmised that the 'sans-serif' entry was a list but I could be mistaken:

import matplotlib
matplotlib.use('PS')
from matplotlib import pylab
import Numeric
N = Numeric
PL = pylab
x = N.arrayrange(100.)
y = N.arrayrange(100.)
fontDict = {'family':'sans-serif',
             'style': 'normal',
             'variant':'normal',
             'weight': 'medium',
             'stretch':'normal',
             'size': 12.0,
             'sans-serif':['Bitstream Vera Sans']}
PL.rc('font',**fontDict)
PL.plot(x,y**2)
PL.savefig('crap')
PL.clf()

--Jim

···

On Mar 28, 2006, at 10:51 AM, Darren Dale wrote:

Please post a full example

On Tuesday 28 March 2006 12:23, you wrote:

I am in the midst of battling the OS X postscript font idiosyncrasies.
I wish to switch to:
  font.sans-serif : Bitstream Vera Sans

so that I can produce usable postscript files. This works fine if I
edit the matplotlibrc file and run the code.
BUT I figured it would be better to do this in the code, since I only
want this for the PS backend.
I thought that the following should produce the same result as editing
the matplotlibrc file but it apparently does not.

fontDict = {'family':'sans-serif',
             'style': 'normal',
             'variant':'normal',
             'weight': 'medium',
             'stretch':'normal',
             'size': 12.0,
             'sans-serif':['Bitstream Vera Sans']}
pylab.rc('font',**fontDict)

What (probably obvious) am I missing?
By the way pylab.rc('text',usetex = True) works fine for me to yield
good PS.

--Jim

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live
webcast and join the prime developer group breaking into this new coding
territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Darren S. Dale, Ph.D.
Cornell High Energy Synchrotron Source
Cornell University
200L Wilson Lab
Rt. 366 & Pine Tree Road
Ithaca, NY 14853

dd55@...163...
office: (607) 255-9894
fax: (607) 255-9001

Your second script works fine for me. I was able to switch the font in the
postscript file, between Bitstream Vera Sans and Arial, by modifying your
fontDict. I'm using svn mpl on linux, but I dont think anything has changed
since 0.87.2 that would effect the results.

Are there any Mac users with a free moment to run his script?

Darren

···

On Tuesday 28 March 2006 19:05, you wrote:

plotlibrc setting:
font.sans-serif : Lucida Grande, Verdana, Geneva, Lucida, Bitstream
Vera Sans, Arial, Helvetica, Avant Garde, sans-serif
I get a postscript file that I cannot view.
BUT if I change the matplotlibrc file to:
font.sans-serif : Bitstream Vera Sans
All goes well and the PS file is fine. This has been discussed on the
list previously as an OS X font issue.

My idea was to use the following code to set the font.sans-serif
dynamically.
However, it does not seem to work in that the ps file is not usable as
if Lucida Grande was still the font.sans-serif setting.
There might well be something very obvious - From the font manager
code I surmised that the 'sans-serif' entry was a list but I could be
mistaken:

import matplotlib
matplotlib.use('PS')
from matplotlib import pylab
import Numeric
N = Numeric
PL = pylab
x = N.arrayrange(100.)
y = N.arrayrange(100.)
fontDict = {'family':'sans-serif',
             'style': 'normal',
             'variant':'normal',
             'weight': 'medium',
             'stretch':'normal',
             'size': 12.0,
             'sans-serif':['Bitstream Vera Sans']}
PL.rc('font',**fontDict)
PL.plot(x,y**2)
PL.savefig('crap')
PL.clf()

Darren and Jim: Works for me on 10.4. -Jeff

···

On Wed, 29 Mar 2006 10:34:08 -0500, "Darren Dale" <dd55@...163...> said:

On Tuesday 28 March 2006 19:05, you wrote:
> plotlibrc setting:
> font.sans-serif : Lucida Grande, Verdana, Geneva, Lucida, Bitstream
> Vera Sans, Arial, Helvetica, Avant Garde, sans-serif
> I get a postscript file that I cannot view.
> BUT if I change the matplotlibrc file to:
> font.sans-serif : Bitstream Vera Sans
> All goes well and the PS file is fine. This has been discussed on the
> list previously as an OS X font issue.
>
> My idea was to use the following code to set the font.sans-serif
> dynamically.
> However, it does not seem to work in that the ps file is not usable as
> if Lucida Grande was still the font.sans-serif setting.
> There might well be something very obvious - From the font manager
> code I surmised that the 'sans-serif' entry was a list but I could be
> mistaken:
>
> import matplotlib
> matplotlib.use('PS')
> from matplotlib import pylab
> import Numeric
> N = Numeric
> PL = pylab
> x = N.arrayrange(100.)
> y = N.arrayrange(100.)
> fontDict = {'family':'sans-serif',
> 'style': 'normal',
> 'variant':'normal',
> 'weight': 'medium',
> 'stretch':'normal',
> 'size': 12.0,
> 'sans-serif':['Bitstream Vera Sans']}
> PL.rc('font',**fontDict)
> PL.plot(x,y**2)
> PL.savefig('crap')
> PL.clf()

Your second script works fine for me. I was able to switch the font in
the
postscript file, between Bitstream Vera Sans and Arial, by modifying your
fontDict. I'm using svn mpl on linux, but I dont think anything has
changed
since 0.87.2 that would effect the results.

Are there any Mac users with a free moment to run his script?

Darren

Thanks for your help. Encouraged by your results I tried some more experiments.
There appears to be some hysteresis in matplotlib fonts ( at least my installation).
Unsaid(!!!) in my message was that I initially ran the PS plot with the default fonts and generated a defective PS file, and then I tried to change the font properties. After running the rc(font, **fontDict) command I still generated a defective file but a different size - so something changed.
However, if I just run the rc(font, **fontDict) command sequence first without ever trying the defaults fonts all goes well and I get a fine PS file.
Evidently, some aspects of the old font are retained.

Thanks again,
--Jim

···

On Mar 29, 2006, at 8:54 AM, jswhit@...1065... wrote:

On Wed, 29 Mar 2006 10:34:08 -0500, "Darren Dale" <dd55@...163...> > said:

On Tuesday 28 March 2006 19:05, you wrote:

plotlibrc setting:
font.sans-serif : Lucida Grande, Verdana, Geneva, Lucida, Bitstream
Vera Sans, Arial, Helvetica, Avant Garde, sans-serif
I get a postscript file that I cannot view.
BUT if I change the matplotlibrc file to:
font.sans-serif : Bitstream Vera Sans
All goes well and the PS file is fine. This has been discussed on the
list previously as an OS X font issue.

My idea was to use the following code to set the font.sans-serif
dynamically.
However, it does not seem to work in that the ps file is not usable as
if Lucida Grande was still the font.sans-serif setting.
There might well be something very obvious - From the font manager
code I surmised that the 'sans-serif' entry was a list but I could be
mistaken:

import matplotlib
matplotlib.use('PS')
from matplotlib import pylab
import Numeric
N = Numeric
PL = pylab
x = N.arrayrange(100.)
y = N.arrayrange(100.)
fontDict = {'family':'sans-serif',
             'style': 'normal',
             'variant':'normal',
             'weight': 'medium',
             'stretch':'normal',
             'size': 12.0,
             'sans-serif':['Bitstream Vera Sans']}
PL.rc('font',**fontDict)
PL.plot(x,y**2)
PL.savefig('crap')
PL.clf()

Your second script works fine for me. I was able to switch the font in
the
postscript file, between Bitstream Vera Sans and Arial, by modifying your
fontDict. I'm using svn mpl on linux, but I dont think anything has
changed
since 0.87.2 that would effect the results.

Are there any Mac users with a free moment to run his script?

Darren

Darren and Jim: Works for me on 10.4. -Jeff