添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
逃跑的键盘  ·  Python while循环-阿里云·  1 年前    · 
机灵的皮蛋  ·  Postgres包: psycopg2 ...·  1 年前    · 
时尚的大葱  ·  C# ...·  1 年前    · 

matplotlib 中文字体 mac

Matplotlib 默认使用的是英文字体,如果需要显示中文字体,需要手动更改字体。

在 Mac 中,可以安装中文字体,例如「SimHei」「STHeiti」等。安装完成后,在 Matplotlib 中通过设置字体名称为「SimHei」「STHeiti」等来显示中文字体。

代码示例:

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']  # 指定中文字体
plt.rcParams['axes.unicode_minus'] = False  # 解决保存图像是负号'-'显示为方块的问题
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.title("中文标题")
plt.xlabel("横轴")
plt.ylabel("纵轴")
plt.show()
  •