在matplotlib中,解决中文乱码问题
2018-03-05 15:33
633 查看
#!/usr/bin/env python3 import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties import numpy as np font = FontProperties(fname='C:\\Windows\\Fonts\\simsun.ttc', size=14) #将(0,10)分成等区间的100份 x=np.linspace(0,10,100) #在matplotlib中使用数学函数的方法 y=np.sin(x) fig=plt.figure() ax=fig.add_subplot(1,1,1) ax.plot(x,y) ax.set_title('正弦函数图',fontproperties=font)plt.show()
这里采用的是matplotlib中的font_manager方法:
(1)先导入font_manager
from matplotlib.font_manager import FontProperties
(2)找到中文字体在电脑中的位置
font = FontProperties(fname='C:\\Windows\\Fonts\\simsun.ttc', size=14)
(3)解决问题:ax.set_title('正弦函数图',fontproperties=font)
效果如图所示:
拓展:如果图例中出现了乱码就这么修改: plt.legend(prop=font)
相关文章推荐
- 解决matplotlib中文乱码问题(Windows)
- 解决matplotlib中文乱码问题(Windows)
- matplotlib解决中文乱码问题
- 西瓜书 习题4.3 编程实现信息熵决策树、绘制决策树、解决matplotlib中文乱码问题
- ubuntu系统下matplotlib中文乱码问题的解决方法
- Ubuntu下matplotlib绘图中文乱码问题的解决
- 彻底解决matplotlib中文乱码问题
- Python 3下使用Matplotlib工具画图,中文显示乱码的问题解决(修改配置文件)
- Mac系统彻底解决matplotlib中文显示乱码的问题
- 解决matplotlib绘图中显示中文乱码的问题
- 彻底解决matplotlib中文乱码问题
- 解决matplotlib中文乱码问题
- matplotlib解决中文乱码问题
- 解决matplotlib中文乱码问题(Ubuntu16.04)
- 彻底解决matplotlib中文乱码问题
- 解决matplotlib中文乱码问题
- 解决matplotlib中文乱码问题
- 彻底解决matplotlib中文乱码问题
- 解决matplotlib中文乱码问题(Windows)
- 解决Windows系统下python利用matplotlib绘图时中文乱码的问题