matplotlib-0.99 font incompatibility?

Hi all,

the following code used to work for me in matplotlib-0.98 to make a
simple scatter plot and change the font from the default font to
Helvetica (I am using mac os x).

import matplotlib
matplotlib.use('PDF')
import matplotlib.pyplot as plt
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
from scipy import *
from numpy import *

my_fig = plt.figure(figsize=(6,5), dpi=100)
x = rand(100)*300
y = rand(100)
plt.scatter(x, y)
plt.rcParams['xtick.direction'] = 'out'
plt.rcParams['ytick.direction'] = 'out'
c = 0.05*300.5
plt.xlim([0-c, 300+c])
plt.ylim([-0.05, 1.05])
plt.savefig('x.pdf')

i recently upgraded to matplotlib-0.99 and the changing of the font
using the above method no longer works. the figure is plotted the
same, but the font remains the default matplotlib font.

one potential problem in the installation was this: i installed
matplotlib-0.99 using the dmg prepackaged binary installer. this
installed matplotlib in the directory:

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages

however, for some reason ipython / python2.5 was looking for packages in:

/Library/Python/2.5/site-packages

and so matplotlib/mpl_toolkits was not found. so I copied the
directories 'matplotlib' and 'mpl_toolkits' from
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages
to /Library/Python/2.5/site-packages. Perhaps this was the cause of
the problem?

thanks for your help.

(i run my code via ipython, by the way.)

i figured out what i did wrong and so am writing it here in case it
helps others.

the basic issue is that the .ttf font was missing in the new
matplotlib directory. to discover this, i ran python with
--verbose-debug as suggested in previous threads by others. then i
copied my version of Helvetica.ttf into:

/Library/Python/2.5/site-packages/matplotlib/mpl-data/fonts/pdfcorefonts

and

/Library/Python/2.5/site-packages/matplotlib/mpl-data/fonts/ttf

then everything worked and i was able to change fonts to helvetica.

thanks.

···

On Sat, Aug 22, 2009 at 7:12 PM, per freem<perfreem@...287...> wrote:

Hi all,

the following code used to work for me in matplotlib-0.98 to make a
simple scatter plot and change the font from the default font to
Helvetica (I am using mac os x).

import matplotlib
matplotlib.use('PDF')
import matplotlib.pyplot as plt
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
from scipy import *
from numpy import *

my_fig = plt.figure(figsize=(6,5), dpi=100)
x = rand(100)*300
y = rand(100)
plt.scatter(x, y)
plt.rcParams['xtick.direction'] = 'out'
plt.rcParams['ytick.direction'] = 'out'
c = 0.05*300.5
plt.xlim([0-c, 300+c])
plt.ylim([-0.05, 1.05])
plt.savefig('x.pdf')

i recently upgraded to matplotlib-0.99 and the changing of the font
using the above method no longer works. the figure is plotted the
same, but the font remains the default matplotlib font.

one potential problem in the installation was this: i installed
matplotlib-0.99 using the dmg prepackaged binary installer. this
installed matplotlib in the directory:

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages

however, for some reason ipython / python2.5 was looking for packages in:

/Library/Python/2.5/site-packages

and so matplotlib/mpl_toolkits was not found. so I copied the
directories 'matplotlib' and 'mpl_toolkits' from
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages
to /Library/Python/2.5/site-packages. Perhaps this was the cause of
the problem?

thanks for your help.

(i run my code via ipython, by the way.)

When you have a problem like this with one install looking one place
and another install looking in another place making a symbolic link is
usually easier and more likely to catch everything than making a copy.
In your case you could have said:

ln -s /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages
/Library/Python/2.5/site-packages

I'm glad you quickly found the root cause.

Phil

···

On Sat, Aug 22, 2009 at 6:36 PM, per freem<perfreem@...287...> wrote:

i figured out what i did wrong and so am writing it here in case it
helps others.

the basic issue is that the .ttf font was missing in the new
matplotlib directory. to discover this, i ran python with
--verbose-debug as suggested in previous threads by others. then i
copied my version of Helvetica.ttf into:

/Library/Python/2.5/site-packages/matplotlib/mpl-data/fonts/pdfcorefonts

and

/Library/Python/2.5/site-packages/matplotlib/mpl-data/fonts/ttf

then everything worked and i was able to change fonts to helvetica.

thanks.

On Sat, Aug 22, 2009 at 7:12 PM, per freem<perfreem@...287...> wrote:

Hi all,

the following code used to work for me in matplotlib-0.98 to make a
simple scatter plot and change the font from the default font to
Helvetica (I am using mac os x).

import matplotlib
matplotlib.use('PDF')
import matplotlib.pyplot as plt
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
from scipy import *
from numpy import *

my_fig = plt.figure(figsize=(6,5), dpi=100)
x = rand(100)*300
y = rand(100)
plt.scatter(x, y)
plt.rcParams['xtick.direction'] = 'out'
plt.rcParams['ytick.direction'] = 'out'
c = 0.05*300.5
plt.xlim([0-c, 300+c])
plt.ylim([-0.05, 1.05])
plt.savefig('x.pdf')

i recently upgraded to matplotlib-0.99 and the changing of the font
using the above method no longer works. the figure is plotted the
same, but the font remains the default matplotlib font.

one potential problem in the installation was this: i installed
matplotlib-0.99 using the dmg prepackaged binary installer. this
installed matplotlib in the directory:

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages

however, for some reason ipython / python2.5 was looking for packages in:

/Library/Python/2.5/site-packages

and so matplotlib/mpl_toolkits was not found. so I copied the
directories 'matplotlib' and 'mpl_toolkits' from
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages
to /Library/Python/2.5/site-packages. Perhaps this was the cause of
the problem?

thanks for your help.

(i run my code via ipython, by the way.)

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users