Skip to content

Instantly share code, notes, and snippets.

@AtomicVar
Created September 26, 2023 13:29
Show Gist options
  • Save AtomicVar/2c1a605537b0b4e5475910b6209c97a5 to your computer and use it in GitHub Desktop.
Save AtomicVar/2c1a605537b0b4e5475910b6209c97a5 to your computer and use it in GitHub Desktop.
FUCK MATPLOTLIB CHINESE DISPLAY
""" 如何让 Matplotlib 正确显示中文 """
""" 第一步:通过字体路径创建一个字体属性对象 """
from matplotlib.font_manager import FontProperties
my_font = FontProperties(fname='/Path/To/Your/Font.ttf')
""" 第二步:在所有需要显示中文的绘图命令中增加 fontproperties=my_font 或 prop=my_font 参数 """
plt.xlabel('线程池线程数', fontproperties=my_font)
plt.ylabel('数据加载吞吐率(图/秒)', fontproperties=my_font)
plt.legend(..., prop=my_font)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment