#!E:\Python\Python37-32\python
#-*-coding:utf-8-*-
import numpy as np 
import matplotlib.dates as mdates
import pylab as plt
import datetime as dt

plt.mpl.rcParams['font.sans-serif'] = ['SimHei'] 
plt.mpl.rcParams['axes.unicode_minus'] = False 

date2_1 = dt.datetime(2020,1,23)
date2_2 = dt.datetime(2020,2,18)
delta2 = dt.timedelta(days=1)
dates2 = mdates.drange(date2_1, date2_2, delta2)

x = np.arange(1, 27, 1)
y = np.array([105,180,323,371,1291,840,1032,1220,1347,1921,2103,2345,3156,2987,2447,2841,2147,2618,2097,1638,14840,2174,2420,1843,1933,1807])
y1 = np.array([ 250,444,680,760,1771,1450,1737,1982,2102,2580,2829,3235,3887,3694,3143,3399,2656,3062,2478,2072,15138,5090,2641,2009,2048,1891])
v = list(map(lambda xx: xx[0]-xx[1], zip(y1, y)))

#date2_2 = dt.datetime(2020,1,28)
#delta2 = dt.timedelta(days=1)
#dates2 = mdates.drange(date2_1, date2_2, delta2)
#x = np.arange(1, 6, 1)
#y = np.array([105,180,323,371,1291])
#y1 = np.array([ 250,444,680,760,1771])

z1 = np.polyfit(x, y, 6)

p1 = np.poly1d(z1)
z2 = np.polyfit(x, y1, 6)

p2= np.poly1d(z2)

z3 = np.polyfit(x, v, 6)

p3= np.poly1d(z3)


plt.figure(figsize=(12, 18))  # 宽800 长600
plt.subplot(311)  # 一行两列,这是第一个图
plt.plot(dates2 , y, 'b', label='武汉确诊')
plt.bar(dates2 , y,width=0.2,facecolor='g')
plt.plot(dates2 ,  p1(x), 'g', label='武汉趋势线')
plt.title('肺炎武汉确诊人数曲线',color='blue', loc='center')
plt.legend()

ax = plt.gca()
for label in ax.xaxis.get_ticklabels():
        label.set_rotation(90)

ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
ax.xaxis.set_major_locator(mdates.DayLocator())

for xx,yy in zip(dates2,y):
        ax.text(xx+0.05,yy+0.05,'%d' %yy, ha='center',va='bottom',rotation=60)

#ax.text(dt.datetime(2020,1,19),2000,'肺炎武汉确诊人数曲线', color='blue',rotation=90)

plt.subplot(312)

plt.plot(dates2 , y1, 'b', label='全国确诊')
plt.bar(dates2 , y1,width=0.2,facecolor='g')
plt.plot(dates2 ,  p2(x), 'g', label='全国趋势线')
plt.title('肺炎全国确诊人数曲线',color='blue')
plt.legend()

ax = plt.gca()
for label in ax.xaxis.get_ticklabels():
        label.set_rotation(90)

ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
ax.xaxis.set_major_locator(mdates.DayLocator())

for xx,yy in zip(dates2,y1):
        ax.text(xx+0.05,yy+0.05,'%d' %yy, ha='center',va='bottom',rotation=60)

#plt.savefig('data3/Kuaizi_Classification1_loss={0:.2f}_accur={1:.2f}_epoch={2}.jpg'.format(val_loss[-1], val_acc[-1], epochs[-1]))

plt.subplot(313)

plt.plot(dates2 , v, 'b', label='其他省确诊')
plt.bar(dates2 , v,width=0.2,facecolor='g')
plt.plot(dates2 ,  p3(x), 'g', label='其他省趋势线')
plt.title('肺炎全国其他省确诊人数曲线',color='blue')
plt.legend()

ax = plt.gca()
for label in ax.xaxis.get_ticklabels():
        label.set_rotation(90)

ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
ax.xaxis.set_major_locator(mdates.DayLocator())

for xx,yy in zip(dates2,v):
        ax.text(xx+0.05,yy+0.05,'%d' %yy, ha='center',va='bottom',rotation=60)
        
        
        
        
plt.subplots_adjust(wspace =0, hspace =0.5)
plt.show()
 

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐