ZhengPeng7

matplotlib 显示中文

Method_1:

# 添上:
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

Method_2:

先定义myfont变量, 使其获取某个本地的字体, 然后在需要显示相应字体的函数中使用fontproperties参数, 赋值myfont即可:

from matplotlib.font_manager import FontProperties
myfont = FontProperties(fname='/usr/share/fonts/truetype/simhei.ttf', size=20)
...
plt.title(SOME_STR, fontproperties=myfont)

Ubuntu中缺少中文字体:

网上下

字体下载网站
下载SimHei入口1
下载SimHei入口2

这里下载下来的是.rar文件, 若系统无rar和unrar, 则以apt-get下载之, 之后将其解压:
rar+unrar使用参考链接

unrar x simheittf.rar

搬运windows中的

C:/Windows/fonts/里面挑选

放至Ubuntu中的路径

/usr/share/fonts/truetype

相关文章:

  • 2021-11-10
  • 2021-12-06
  • 2021-08-02
  • 2022-01-16
  • 2022-12-23
  • 2022-02-10
猜你喜欢
  • 2021-07-26
  • 2021-06-28
  • 2021-04-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案