欧酷网

您的位置:主页>算法>

【肺炎python数据图】武汉、全国、其他省截至2-12日最新数据

 

#!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,13)
delta2 = dt.timedelta(days=1)
dates2 = mdates.drange(date2_1, date2_2, delta2)
 x = np.arange(1, 22, 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])
y1 = np.array([ 250,444,680,760,1771,1450,1737,1982,2102,2580,2829,3235,3887,3694,3143,3399,2656,3062,2478,2072,15138])
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, 5.5))  # 宽800 长600
plt.subplot(131)  # 一行两列,这是第一个图
plt.plot(dates2 , y, 'b', label='武汉确诊')
plt.bar(dates2 , y,width=0.2,facecolor='g')
plt.plot(dates2 ,  p1(x), 'g', label='武汉趋势线')
plt.title('肺炎武汉确诊人数曲线')
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')
 plt.subplot(132)
 plt.plot(dates2 , y1, 'b', label='全国确诊')
plt.bar(dates2 , y1,width=0.2,facecolor='g')
plt.plot(dates2 ,  p2(x), 'g', label='全国趋势线')
plt.title()

 

相关文章推荐