From: John H. <jd...@gm...> - 2008-09-13 16:39:31
|
On Sat, Sep 13, 2008 at 4:35 AM, sa6113 <s.p...@gm...> wrote: > > I want to set all font system to my texts, but I can't set all the fonts. I > am using this code: > > font = FontProperties( size='small' ,fname = 'Tahoma' ) > self.ax.legend( line, label, legend , prop = font ) > > It raises this error : > font = FT2Font(str(fname)) > RuntimeError: Could not open facefile Tahoma; Cannot_Open_Resource > > Should I add a font family for that before? How? I doubt that "Tahoma" is the filename, which is what the fname argument is looking for. You need to pass a full path (eg a file ending in .ttf' if you want to explicitly set the font. Eg:: import matplotlib.font_manager as fm import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax.plot([1,2,3], label='test') ax.legend(prop=fm.FontProperties(fname='c:/windows/fonts/tahoma.ttf')) plt.show() But usually you would rather set the font family properties globally, for example using the rc params setting as in the following:: from matplotlib import rcParams rcParams['font.sans-serif'] = ['Tahoma'] import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax.plot([1,2,3], label='test') ax.legend() plt.show() When you run the scripts, you can pass --verbose-debug to the command line to get additional information about what fonts are being loaded, eg C:\> c:/python25/python font_family.py --verbose-debug JDH |