首页 > 编程语言 > 详细

python 单独设置在plot每条线的label为中文

时间:2020-05-12 15:48:36      阅读:201      评论:0      收藏:0      [点我收藏+]

部分代码如下:

fig,(scatter,plot) = plt.subplots(1,2,figsize=(16,8))
scatter.scatter(range(len(data)),np.true_divide(data[::-1,2],data[::-1,3]))
scatter.plot([1]*len(data),label=‘1/1‘)
scatter.set_xticks(range(len(data)))
scatter.set_xticklabels(data[::-1,0],fontproperties=‘Kaiti‘,fontsize=‘13‘,rotation=-90)
scatter.legend(loc=‘best‘)
scatter.set_ylabel(‘男/女‘,fontproperties=‘Kaiti‘,fontsize=‘20‘)
scatter.set_xlabel(‘年份‘,fontproperties=‘Kaiti‘,fontsize=‘20‘)
scatter.set_title(‘男女比例随时间变化图‘,fontproperties=‘Kaiti‘,fontsize=‘25‘)

plot.plot(data[::-1,4],color="R",label=‘城镇‘)
plot.plot(data[::-1,5],color="B",label=‘农村‘)
plot.set_xticks(range(len(data)))
plot.set_xticklabels(data[::-1,0],fontproperties=‘Kaiti‘,fontsize=‘13‘,rotation=-90)
plot.set_ylabel(‘人口(万人)‘,fontproperties=‘Kaiti‘,fontsize=‘20‘)
plot.set_xlabel(‘年份‘,fontproperties=‘Kaiti‘,fontsize=‘20‘)
plot.set_title(‘城镇、农村人口随时间变化图‘,fontproperties=‘Kaiti‘,fontsize=‘25‘)
plt.legend(loc=‘best‘,prop={‘family‘:‘SimHei‘,‘size‘:14})
plt.show()

 

 

在一般的如刻度上,我们可以设置其属性fontproperties用以局部设置显示中文,但是对于plot的label属性这样的设置会有问题,解决方法如下:

plt.legend(prop={‘family‘:‘SimHei‘,‘size‘:14})

在放置图例的时候进行prop设置

 

python 单独设置在plot每条线的label为中文

原文:https://www.cnblogs.com/swust-rjgc-1705-monitor/p/12876609.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!