change matplotlib's default font

后端 未结 4 1628
粉色の甜心
粉色の甜心 2020-12-14 16:26

I\'m trying to change matplotlib\'s default font to Helvetica Neue. On my Mac with EPD/Canopy everything worked fine some time ago.

Trying to do the same on ubuntu

4条回答
  •  有刺的猬
    2020-12-14 16:53

    Kim already introduced dynamic solution works perfectly, and here's two other ways doing the same in static.

    First, you may put a line to rc file for matplotlib . Refer to this page for more information about locating the file and detailed settings.

    font.family : NanumGothic
    

    Second, if you are working with ipython, you can put some commands for font setting to a configuration file for the interactive shell. Find the file named ipython_config.py which usually located under ~/.ipython/somewhere. Then add two more lines to the list, c.InteractiveShellApp.exec_lines .

    c.InteractiveShellApp.exec_lines = [
        "import matplotlib as mpl",
        "mpl.rcParams['font.family'] = 'NanumGothic'"
    ]
    

    Former always works whatever environment you run your shell script on as it loads the font when your script imports matplotlib .

提交回复
热议问题