3

According to the official doc, I can load a custom rc file by creating a matplotlibrc file under ~/.matplotlib/ (I am on a Mac). After I did that, I can verify that my current notebook is loading from the newly created rc file:

In [6]: mlab.matplotlib_fname()
Out[6]: '/Users/cheng/.matplotlib/matplotlibrc'

The problem is that I have defined some extra font for the sans-serif type:

font.family         : sans-serif
font.sans-serif     : PingFang SC, Hiragino Sans GB, Microsoft YaHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif

When I check the value of the font.sans-serif, here is what I get:

In [4]: mlab.rcParams['font.sans-serif']
Out[4]: ['Arial', 'Liberation Sans', 'Bitstream Vera Sans', 'sans-serif']

I don't understand why the rc file is loaded but the font settings are not set according to the file.

Any suggestions?


Update:

I changed the font value manually:

In [4]: mlab.rcParams['font.sans-serif'] = 'PingFang SC, Hiragino Sans GB, Microsoft YaHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif'
In [4]: mlab.rcParams['font.sans-serif']
Out[4]: ['PingFang SC',
         'Hiragino Sans GB',
         'Microsoft YaHei',
         'Bitstream Vera Sans',
         'Lucida Grande',
         'Verdana',
         'Geneva',
         'Lucid',
         'Arial',
         'Helvetica',
         'Avant Garde',
         'sans-serif']

But when I draw a plot, Chinese characters (the ones that I added manually) still shows up as square blocks. It seems that configuring the font.sans-serif setting does not make any differences.

Cheng
  • 16,824
  • 23
  • 74
  • 104
  • You checked whether manually changing the `font.sans-serif` value after loading the default rcparams works, right? I think it just gives a warning and uses the default if the fonts can't be found. – StefanS Sep 05 '16 at 07:06
  • @StefanS please see update – Cheng Sep 05 '16 at 07:12
  • In that case I'd suggest changing the title, because the primary problem seems to be that the fonts don't work. Sadly, I can't help with that. – StefanS Sep 05 '16 at 07:17
  • 1
    Does [this](http://stackoverflow.com/questions/16574898/how-to-load-ttf-file-in-matplotlib-using-mpl-rcparams) question help? It may be that the name you are specifying isn't actually the internal name stored in the .ttf file. – SiHa Sep 05 '16 at 07:26
  • @SiHa Thanks for the link. The second method of that post works but not the first. So it seems that there is something wrong with loading and manually changing rc setting. – Cheng Sep 05 '16 at 07:35

0 Answers0