matplotlib的默认字体_更改matplotlib的默认字体

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 now and it's not working.

This is what I did:

Installed Helvetica Neue

$ fc-match 'Helvetica Neue':Light

HelveticaNeue-Light.otf: "Helvetica Neue" "細體"

Converted the odt/dfont into ttf:

fondu -show HelveticaNeue.dfont

changed matplotlibrc to

$ cat ~/.config/matplotlib/matplotlibrc

...

font.family: Helvetica Neue

I also tried with:

font.family: sans-serif

font.sans-serif: Helvetica Neue

I removed the font cache

rm ~/.config/matplotlib/fontList.cache

But none of these steps are working for me.

$ python -c 'from matplotlib import pyplot as plt; plt.plot(1); plt.savefig("/tmp/test.png")'

/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/font_manager.py:1236:

UserWarning: findfont: Font family ['Helvetica Neue'] not found. Falling back to Bitstream Vera Sans

(prop.get_family(), self.defaultFamily[fontext]))

Version is 1.3.0

$ python -c 'import matplotlib; print matplotlib.__version__'

1.3.0

I also tried moving the fonts to ~/.config/matplotlib/fonts/ttf but it didn't work.

EDIT:

As suggested I tried selecting a specific font for a specific text.

import matplotlib as mpl

mpl.use('Agg')

import matplotlib.pyplot as plt

import matplotlib.font_manager as font_manager

path = '/home//.fonts/HelveticaNeue.ttf'

prop = font_manager.FontProperties(fname=path)

prop.set_weight = 'light'

mpl.rcParams['font.family'] = prop.get_name()

mpl.rcParams['font.weight'] = 'light'

fig, ax = plt.subplots()

ax.set_title('Text in a cool font', fontproperties=prop, size=40)

plt.savefig('/tmp/test2.png')

But it makes no difference.

/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/font_manager.py:1236:

UserWarning: findfont: Font family ['Helvetica Neue'] not found. Falling back to Bitstream Vera Sans

However I seem to experience this problem only with this Helvetica/Helvetica Neue font.

(prop.get_family(), self.defaultFamily[fontext]))

解决方案

This won't change you font permanently, but it's worth a try

matplotlib.rc('font', family='sans-serif')

matplotlib.rc('font', serif='Helvetica Neue')

matplotlib.rc('text', usetex='false')

matplotlib.rcParams.update({'font.size': 22})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值