from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
import numpy as np
x =[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
y1=[0.1975, 0.1942, 0.1895, 0.1848, 0.1660, 0.1645, 0.1646, 0.1641, 0.1649, 0.1652, 0.1664, 0.1680, 0.1686]
y2=[0.7232, 0.7253, 0.7280, 0.7305, 0.7453, 0.7443, 0.7415, 0.7392, 0.7345, 0.7301, 0.7251, 0.7182, 0.7120]
y3=[0.0793, 0.0805, 0.0825, 0.0847, 0.0887, 0.0912, 0.0939, 0.0967, 0.1006, 0.1047, 0.1085, 0.1139, 0.1194]
#绘制0-14岁人口所占比例插值图
from scipy.interpolate import spline
plt.figure(figsize=(8,6))
x_new = np.linspace(min(x),max(x),100)
y_smooth = spline(x, y1, x_new)
plt.ylim((0.16, 0.20))
my_y_ticks = np.arange(0.16, 0.201,0.005)
plt.yticks(my_y_ticks)
plt.plot(x_new, y_smooth)
plt.xticks((1,2,3,4,5,6,7,8,9,10,11,12,13),('2006年','2007年','2008年','2009年','2010年','2011年','2012年','2013年',
'2014年','2015年','2016年','2017年','2018年'))
def baifenbi(temp,position):
return"%.1f"%(100*temp)+"%"
plt.gca().yaxis.set_major_formatter(FuncFormatter(baifenbi))
plt.xlabel('年份')
plt.ylabel('0-14岁人口占总人口比例')
plt.show()
#绘制15-64岁人口所占比例插值图
from scipy.interpolate import spline
plt.figure(figsize=(8,6))
x_new = np.linspace(min(x),max(x),100)
y_smooth = spline(x, y2, x_new)
plt.ylim((0.70, 0.76))
my_y_ticks = np.arange(0.70, 0.76,0.005)
plt.yticks(my_y_ticks)
plt.plot(x_new, y_smooth)
plt.xticks((1,2,3,4,5,6,7,8,9,10,11,12,13),('2006年','2007年','2008年','2009年','2010年','2011年','2012年','2013年',
'2014年','2015年','2016年','2017年','2018年'))
def baifenbi(temp,position):
return"%.1f"%(100*temp)+"%"
plt.gca().yaxis.set_major_formatter(FuncFormatter(baifenbi))
plt.xlabel('年份')
plt.ylabel('15-64岁人口占总人口比例')
plt.show()
#绘制65岁及以上人口所占比例插值图
from scipy.interpolate import spline
plt.figure(figsize=(8,6))
x_new = np.linspace(min(x),max(x),100)
y_smooth = spline(x, y3, x_new)
plt.ylim((0.07, 0.13))
my_y_ticks = np.arange(0.07, 0.130001,0.01)
plt.yticks(my_y_ticks)
plt.plot(x_new, y_smooth)
plt.xticks((1,2,3,4,5,6,7,8,9,10,11,12,13),('2006年','2007年','2008年','2009年','2010年','2011年','2012年','2013年',
'2014年','2015年','2016年','2017年','2018年'))
def baifenbi(temp,position):
return"%.1f"%(100*temp)+"%"
plt.gca().yaxis.set_major_formatter(FuncFormatter(baifenbi))
plt.xlabel('年份')
plt.ylabel('65岁及以上人口占总人口比例')
plt.show()
运行效果如下:
欢迎加群:620139909