部分代码如下:

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设置