[Python least squares polynomial fitting method to calculate the predicted update] diagnosed with pneumonia Wuhan national trend comparison chart (the latest as of 2020-2-6)


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)
  1. date2_2 = dt.datetime(2020,2,7)
delta2 = dt.timedelta (days = 1 )
dates2 = mdates .drange (date2_1, date2_2, delta2)
 
x = np.arange(1, 16, 1)
y = np.array([105,180,323,371,1291,840,1032,1220,1347,1921,2103,2345,3156,2987,2447])
y1 = np.array([ 250,444,680,760,1771,1450,1737,1982,2102,2580,2829,3235,3887,3694,3143])
z1 = np.polyfit(x, y, 6)

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

p2= np.poly1d(z2)
 
plt.figure (figsize = (12, 5.5 )) # width 800 length 600
plt.subplot (121) # line two, which is the first in FIG
plt.plot (
dates2 , Y, 'B', label = 'Wuhan diagnosis')
plt.plot ( dates2 , P1 (X), 'G', label = 'Wuhan trendline')
plt.title ( 'Wuhan number of people diagnosed with pneumonia curve')
plt.legend ()
 
max = 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())
 

plt.subplot (122)

plt.plot ( dates2 , Y1, 'B', label = 'National confirmed')
plt.plot ( dates2 , P2 (X), 'G', label = 'National trend line ")
plt.title ( 'the country the number of diagnosed pneumonia curve')
plt.legend ()
 
max = 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())
 
#plt.savefig('data3/Kuaizi_Classification1_loss={0:.2f}_accur={1:.2f}_epoch={2}.jpg'.format(val_loss[-1], val_acc[-1], epochs[-1]))
 
plt.show()
 
 
Published 439 original articles · won praise 35 · views 90000 +

Guess you like

Origin blog.csdn.net/viviliving/article/details/104210852