osx backend does not allow font changes #1038

Closed
CRP opened this Issue Jul 24, 2012 · 12 comments

Comments

Projects
None yet
4 participants

CRP commented Jul 24, 2012

The default font for all text is always Times, and there is no way to change that. If I try, for example, pyplot.title('MyChart',fontname='Courier'), the title is written in Times. Works fine with other backends.

my matplotlib version is latest from git.

Owner

mdboom commented Jul 30, 2012

@mdehoon: Any thoughts?

Contributor

mdehoon commented Jul 30, 2012

Works fine for me...

CRP commented Jul 30, 2012

I have tried deleting .matplotlib/matplotlibrc, but to no avail.

If I start ipython with --pylab=osx the font in charts is serif, if I start it with --pylab=tk I get sans serif fonts.

What should I check in my system to find out what is forcing the font with osx backend?

Thanks

Contributor

mdehoon commented Jul 30, 2012

Can you try with plain Python instead of ipython? With plain Python, I don't observe either of the two issues.

CRP commented Jul 31, 2012

same behaviour on plain python. Is there anywhere else settings for matplotlib are defined? As I mentioned, I got rid of matplotlibrc...

Contributor

mdehoon commented Jul 31, 2012

You could try and have a look at what is happening in the draw_text method in
lib/matplotlib/backends/backend_macosx.py
That can tell you if the problem occurs within the Mac OS X backend, or if the call into the backend already has the wrong font name.

CRP commented Aug 1, 2012

The prop variable which, if I understand things correctly, contains the parameters for the font, specifies "Bitstream Vera Sans" as the font throughout the execution, ie both before and after entering the backend_macosx piece.
Initially I did not have that font on my system (at least according to Font Book). So I though that maybe the code silently falls back to a serif font, and installed the font. But for some reason the draw_text method still paints a serif font.
while debugging, if I break at line 145 of the file you mention, which contains the statement:
gc.draw_text(x, y, unicode(s), family, size, weight, style, angle)
I have following values:
family='sans_serif'
weight=style='normal'
I have tried to go on stepping into all possible functions, but could not find a place where the font is changed.
So I guess the question becomes:

  1. Is it correct that Bitstream Vera Sans is defined as default font even if it is not installed on the system? Does this font come with Mac OSX? I do not recall uninstalling it.
  2. why is a serif font used even if rcParams['font.family']='sans-serif', and it stays this way throughout execution?
  3. I tried playing with rcParams, and changing font.size produces the desired effect, while changing font.family, font.style is apparently ignored.

CRP commented Aug 1, 2012

I now see that font.sans-serif contais a list of fonts, a few of which are installed on my system, but they are all correctly sans-serif fonts, so no idea why it falls back to a serif dont.

CRP commented Aug 1, 2012

I just tried the following:

  1. rcParams['font.sans-serif']=['Verdana']
  2. plot(randn(10))
  3. gca().get_xticklabels()[0].get_fontname() returns 'Verdana'
    So everything appears fine under the hood, but the font on display is definitely not Verdana. Here is a screenshot:
    http://imageshack.us/photo/my-images/827/serif.pdf/
Contributor

mdehoon commented Aug 2, 2012

I am afraid your only option is to look at the draw_text method in src/_macosx.m to see what is happening. This method makes a call to setfont; probably something is going wrong there.

CRP commented Aug 3, 2012

I just reinstalled matplotlib from git and the problem disappeared. go figure...

Contributor

mdehoon commented Dec 12, 2012

Then let's close this issue. Any objections, anybody?

pelson closed this Dec 12, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment