27 April 2015

solution

  1. use FontBook app to install msyh.ttf

  2. edit your matplotlibrc file

    1. find out matplotlibrc file

       $ python -c "import matplotlib; print matplotlib.matplotlib_fname()"
       /Users/hqlgree2/anaconda/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc
      
    2. copy this file to your home folder

       $ cd /Users/hqlgree2/anaconda/lib/python2.7/site-packages/matplotlib/mpl-data/
       $ cp matplotlibrc ~/.matplotlib/matplotlibrc
      
    3. make some edit and save

       $ pico matplotlibrc
       # uncomment this line
       font.family : sans-serif
      
       # uncomment this line and add Microsoft YaHei
       font.sans-serif : Microsoft YaHei, Bitstream Vera Sans...
      
  3. regenerate fontList.cache

         $ cd ~/.matplotlib
         $ rm fontList.cache
    
         $ python -c "import matplotlib.pyplot as plt"
    
         $ grep YaHei fontList.cache
         S'Microsoft YaHei'
    
  4. use font in code

         import matplotlib
         matplotlib.rcParams['font.sans-serif'] = ['Microsoft YaHei']
         matplotlib.rcParams['axes.unicode_minus'] = False
    

convert .dfont to .ttf

  1. install fondu use brew

         $ brew install fondu
         # if got an error run brew update
    
  2. convert

         $ cd some_dir
         $ sudo fondu -show /System/Library/Fonts/Helvetica.dfont
    

convert .ttc to .ttf

  1. download dfontsplitter

  2. drag .ttc file into dfontsplitter app

find font on your system

  1. you can use FontBook.app

  2. check my 2015-04-27-mac-font-locations-and-their-purposes

find where matplotlib stores its data

        $ python
        >>> import matplotlib
        >>> matplotlib.matplotlib_fname()
        /Users/hqlgree2/anaconda/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc
        or

        $ python -c "import matplotlib; print matplotlib.matplotlib_fname()"
        /Users/hqlgree2/anaconda/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc


blog comments powered by Disqus