python matplotlib jupyter中绘图使用宋体
Jupyter中使用宋体
在jupyter notebook中用matplotlib绘图会有汉字字体不显示的问题,而我们日常绘图中会有中文标题、坐标轴的需求。
解决方法为在坐标轴label中的fontproperties字段中增加宋体的属性。
import matplotlib
import matplotlib.pyplot as plt
#导入字体库中的宋体
Songti = matplotlib.font_manager.FontProperties(fname='C:\Windows\Fonts\simsun.ttc')
plt.plot([1,2,3,4])
plt.xlabel('X 轴', fontproperties = Songti, fontsize = 14)
plt.ylabel('Y 轴', fontproperties = Songti, fontsize = 14)
plt.show()
![](https://img-blog.csdnimg.cn/20200112151609511.png)