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
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
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
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
···
On Sun, Sep 14, 2008 at 1:30 AM, sa6113 <s.payandeh@...287...> 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 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
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::
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
···
On Mon, Sep 15, 2008 at 7:13 AM, sa6113 <s.payandeh@...287...> 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.
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