Created
September 26, 2023 13:29
-
-
Save ZJUGuoShuai/2c1a605537b0b4e5475910b6209c97a5 to your computer and use it in GitHub Desktop.
FUCK MATPLOTLIB CHINESE DISPLAY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 如何让 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