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.