matplotlib 如何解决中英混排

2016-11-02 11:42:08 +08:00
 wisefree
请教大家一个问题,困扰我好几天了,:)
matplotlib 中文显示不出来,修改了 matplotlibrc 文件,将字体改成了宋体。修改后生成的图片,中文和英文都是宋体,这样就很不美观,能够设置中文为宋体,英文为 Times New Roman 呢?
有没有参考的思路呢?
2450 次点击
所在节点    Python
4 条回复
justou
2016-11-02 12:45:21 +08:00
这样的?


# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties

song_ti = FontProperties(fname=r'C:\Windows\Fonts\simsun.ttc', size=20)
times_new_roman = FontProperties(fname=r'C:\Windows\Fonts\times.ttf', size=15)
ax = plt.gca()
ax.set_title(u'能量随时间的变化', fontproperties=song_ti)
ax.set_xlabel('Time (s)', fontproperties=times_new_roman)
ax.set_ylabel('Energy (J)', fontproperties=times_new_roman)
plt.show()
wisefree
2016-11-02 16:39:52 +08:00
@justou 如何得到 fonts 对应的文件名呢? simusun.ttc 在 fonts 文件夹下看不到
网上搜索了一下,请问用 python 能实现么?
justou
2016-11-02 16:55:30 +08:00
C:\Windows\Fonts 文件夹下右键看属性, 没有属性的是字体系列, 双击打开它看里面每个字体文件的属性, 里面有该字体的名字。
wisefree
2016-11-02 18:12:31 +08:00
@justou 网上搜的结果,全部没有这个方法方便,谢谢啦:)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/317361

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX