From: sa6113 <s.p...@gm...> - 2008-09-13 09:40:20
|
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? -- View this message in context: http://www.nabble.com/set-font-problem.-tp19468970p19468970.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
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 |
From: sa6113 <s.p...@gm...> - 2008-09-14 06:30:36
|
Thanks for your help, it works, but it is very difficult because I want to show a FontDialog contains all fonts in system to user and change the plot text (Legend, Label and ex.) font to that. How may I accomplish that? Is there any way? sa6113 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? > -- View this message in context: http://www.nabble.com/set-font-problem.-tp19468970p19477669.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
From: John H. <jd...@gm...> - 2008-09-14 14:56:01
|
On Sun, Sep 14, 2008 at 1:30 AM, sa6113 <s.p...@gm...> wrote: > > Thanks for your help, it works, but it is very difficult because I want to > show a FontDialog contains all fonts in system to user and change the plot > text (Legend, Label and ex.) font to that. > How may I accomplish that? Is there any way? I am not sure precisely what difficulty you are having, but if you are trying to change the font family for *subsequent* figures after the user has made their font choice in the dialog, then the rc setting will work fine. If you are trying to change an existing figure, then rc will not help, but findobj will. findobj recursive searches a figure for all the objects in contains, and you can filter for object type. So you could do something like import matplotlib.text as text for t in fig.findobj(text.Text): t.set_family(somefamily) or t.set_fontproperty(someprop), etc... If you want to keep the font property (size, weight) as is and only change the file name, the following may work for some cases prop = t.get_font_properties() prop.set_file(fname) but this is fairly dangerous (because you could be mixing a monoface style with a non monospace font family for example) so it is not recommended. JDH |
From: sa6113 <s.p...@gm...> - 2008-09-15 12:13:49
|
I think I have to explain it more clear, I want to show a fontdialog to the user contain font name, style, size and some effect, and user will be able select all these changes for legend and axis labels separately, then I want to effect these items to my plot as you know user has very different options and it will be difficult to use font's path. Is that possible to set all those options are selected by user in fontdialog box to the plot?? If it is. How? I would be thankful if you help me. sa6113 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? > -- View this message in context: http://www.nabble.com/set-font-problem.-tp19468970p19491749.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
From: John H. <jd...@gm...> - 2008-09-15 12:56:49
|
On Mon, Sep 15, 2008 at 7:13 AM, sa6113 <s.p...@gm...> wrote: > > I think I have to explain it more clear, I want to show a fontdialog to the > user contain font name, style, size and some effect, and user will be able > select all these changes for legend and axis labels separately, then I want > to effect these items to my plot as you know user has very different options > and it will be difficult to use font's path. > > Is that possible to set all those options are selected by user in fontdialog > box to the plot?? > > If it is. How? I would be thankful if you help me. Yes, this is easily doable. The fond obj command works on any matplotlib instance, so for example, if you wanted to selectively change the text properties of the xaxis:: # see matplotlib.text.Text for information about the settable properties at # http://matplotlib.sourceforge.net/doc/html/api/artist_api.html#matplotlib.text.Text for t in ax.xaxis.findobj(text.Text): t.set_fontstyle('something') t.set_fontsize(12) for the legend you would do the same::: leg = ax.get_legend() for t in leg.findobj(text.Text): # set some properties here All the text setters just forward the calls onto the FontProperties object (see matplotlib.font_manager.FontProperties) so take a look at this object to see what is available. Eg, from my previous post, you can set the fontname explicitly with:: prop.set_file('somefile.ttf') JDH |
From: sa6113 <s.p...@gm...> - 2008-09-16 01:22:51
|
While using this code I get an error saying : Figure instance has no attribute 'findobj' I found that, I need a new version of mpl that install on python 2.4 and higher but I used python 2.3 and I can't upgrade that. would you plz tell me that may I accomplish that witout findobject?? How? Thanks alot for your help. sa6113 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? > -- View this message in context: http://www.nabble.com/set-font-problem.-tp19468970p19507410.html Sent from the matplotlib - users mailing list archive at Nabble.com. |