This topic created in 3491 days ago, the information mentioned may be changed or developed.
请教大家一个问题,困扰我好几天了,:)
matplotlib 中文显示不出来,修改了 matplotlibrc 文件,将字体改成了宋体。修改后生成的图片,中文和英文都是宋体,这样就很不美观,能够设置中文为宋体,英文为 Times New Roman 呢?
有没有参考的思路呢?
4 replies • 2016-11-02 18:12:31 +08:00
 |
|
1
justou Nov 2, 2016 3
这样的?
# -*- 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()
|
 |
|
2
wisefree Nov 2, 2016
@ justou 如何得到 fonts 对应的文件名呢? simusun.ttc 在 fonts 文件夹下看不到 网上搜索了一下,请问用 python 能实现么?
|
 |
|
3
justou Nov 2, 2016 1
C:\Windows\Fonts 文件夹下右键看属性, 没有属性的是字体系列, 双击打开它看里面每个字体文件的属性, 里面有该字体的名字。
|