|
From: James B. <bo...@ll...> - 2006-03-28 17:23:17
|
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
|
|
From: James B. <bo...@ll...> - 2006-03-29 00:05:54
|
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
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
> --
> Darren S. Dale, Ph.D.
> Cornell High Energy Synchrotron Source
> Cornell University
> 200L Wilson Lab
> Rt. 366 & Pine Tree Road
> Ithaca, NY 14853
>
> dd...@co...
> office: (607) 255-9894
> fax: (607) 255-9001
>
|
|
From: Darren D. <dd...@co...> - 2006-03-29 15:34:11
|
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
|
|
From: <js...@fa...> - 2006-03-29 16:55:07
|
On Wed, 29 Mar 2006 10:34:08 -0500, "Darren Dale" <dd...@co...>
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
|
|
From: James B. <bo...@ll...> - 2006-03-29 20:55:30
|
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, js...@fa... wrote:
>
> On Wed, 29 Mar 2006 10:34:08 -0500, "Darren Dale" <dd...@co...>
> 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
>
|
|
From: John H. <jdh...@ac...> - 2006-03-29 21:29:50
|
>>>>> "James" == James Boyle <bo...@ll...> writes:
James> changed. However, if I just run the rc(font, **fontDict)
James> command sequence first without ever trying the defaults
James> fonts all goes well and I get a fine PS file. Evidently,
James> some aspects of the old font are retained.
Are these effects observed within a single python session (all tests
in one script or a single interactive session from the shell).
matplotlib does cache some font information within a single run.
If it is *between* python sessions, you might want to try clearing the
font cache between runs and see if this makes a difference
> rm -rf ~/.matplotlib/ttffont.cache
JDH
|
|
From: James B. <bo...@ll...> - 2006-03-29 22:44:11
|
The effects are observed from with a single python session. Out of curiosity - Is there any way of clearing the cache within a session ? Thanks --Jim On Mar 29, 2006, at 1:27 PM, John Hunter wrote: >>>>>> "James" == James Boyle <bo...@ll...> writes: > James> changed. However, if I just run the rc(font, **fontDict) > James> command sequence first without ever trying the defaults > James> fonts all goes well and I get a fine PS file. Evidently, > James> some aspects of the old font are retained. > > Are these effects observed within a single python session (all tests > in one script or a single interactive session from the shell). > matplotlib does cache some font information within a single run. > > If it is *between* python sessions, you might want to try clearing the > font cache between runs and see if this makes a difference > >> rm -rf ~/.matplotlib/ttffont.cache > > JDH > |
|
From: John H. <jdh...@ac...> - 2006-03-30 01:02:00
|
>>>>> "James" == James Boyle <bo...@ll...> writes:
James> The effects are observed from with a single python session.
James> Out of curiosity - Is there any way of clearing the cache
James> within a session ?
OK, I think I see what is going on. text.Text is calling
FigureCanvas.draw_text with a font_manager.FontProperties instance.
backend_ps is using the __hash__ method of the FontProperties class to
create a cache mapping the font property to the ttf font found in the
RendererPS._get_font_ttf method.
def _get_font_ttf(self, prop):
key = hash(prop)
font = _fontd.get(key)
if font is None:
fname = fontManager.findfont(prop)
font = FT2Font(str(fname))
_fontd[key] = font
if fname not in _type42:
_type42.append(fname)
font.clear()
size = prop.get_size_in_points()
font.set_size(size, 72.0)
return font
the hash(prop) call as noted above calls the __hash__ method of the
FontProperties
def __hash__(self):
return hash( (
tuple(self.__family), self.__style, self.__variant,
self.__weight, self.__stretch, self.__size,
self.__parent_size, self.fname))
My first guess w/o looking further was that the "family" entry is
'sans-serif' but not the actual font list (eg Lucida versus Bitstream)
and this is the source of your woes. Basically, we need to make the
hash method smarter to take account of the actual family list.
You might insert some debug print statements into the font_manager
class to see what this tuple being passed to hash actually is.
On second glance, the family seems to be set properly
if family is None: family = rcParams['font.'+rcParams['font.family']]
if rcParams['font.family]' is 'sans-serif', then family should be
rcParams['font.sans-serif'] which is what we want since this is your
new list. But this is only on the family=None branch, so we need to
find out if a) it is working like it should on this branch and b) what
is being passed if family is not None.
You asked about clearing the cache:
import matplotlib.backends.backend_ps as ps
ps._fontd = {}
Let us know what you find out...
JDH
|