直接上代码
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
x = np.array([8021, 7577, 7118, 7518, 10029, 12850, 10146, 9724, 11771, 12391, 10422, 7697, 7814, 5485, 3632,
2652, 1634, 721, 218, 44]) #2015年
y = np.array([8292, 7685, 7371, 7192, 8883, 12223, 10798, 10020, 10646, 12802, 11745, 6533, 8259, 6257, 3956,
2737, 1785, 802, 238, 55]) #2017年
plt.figure(figsize=(12,8))
plt.barh(range(len(y)), -x,color='darkorange',label='2015年')
plt.barh(range(len(x)), y,color='limegreen',label='2017年')
plt.xlim((-15000,15000))
plt.xticks((-15000,-10000,-5000,0,5000,10000,15000),('15000','10000','5000','0','5000','10000','15000'))
plt.yticks((0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19),
('0-4岁', '5-9岁', '10-14岁', '15-19岁', '20-24岁', '25-29岁', '30-34岁', '35-39岁',
'40-44岁', '45-49岁', '50-54岁', '55-59岁', '60-64岁', '65-69岁', '70-74岁', '75-79岁',
'80-84岁', '85-89岁', '90-94岁', '95以上'))
plt.xlabel('人口数量(万)')
plt.legend()
plt.show()