Matplotlib 中文显示:简单教程及代码示例
Matplotlib 中文显示:简单教程及代码示例
想要在 Matplotlib 图表中显示中文,需要进行以下步骤操作:
1. 安装中文字体库
!sudo apt-get install -y fonts-wqy-zenhei
2. 引入中文字体
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = ['WenQuanYi Micro Hei']
3. 绘制图表
plt.plot([1,2,3],[4,5,6])
plt.title('这是中文标题')
plt.xlabel('横轴')
plt.ylabel('纵轴')
plt.show()
通过以上步骤,您就能在 Matplotlib 图表中成功显示中文。
原文地址: https://www.cveoy.top/t/topic/oxIw 著作权归作者所有。请勿转载和采集!