Skip to content

Instantly share code, notes, and snippets.

@SuperCipher
Created January 6, 2021 16:57
Show Gist options
  • Save SuperCipher/1e8f306dd16072262cb6f11ba4670091 to your computer and use it in GitHub Desktop.
Save SuperCipher/1e8f306dd16072262cb6f11ba4670091 to your computer and use it in GitHub Desktop.
Test Thailand coronavirus graph fitting
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
# %matplotlib inline
x = [46,67,81,110,121,144,155,250,194,279,216,315,745,527]
j = 0
buckets = [0] * len(x)
m = 0
for i in x:
m += i
buckets[j] = m
j += 1
buckets
y = list(range(1, len(x)+1))
# plt.plot( y,x)
# plt.plot( y,buckets)
# def exponential(x, a, b):
# return a*np.exp(b*x)
x = np.array(y)
y = np.array(buckets)
# Function to calculate the exponential with constants a and b
def func(x, a, b):
return a * np.exp(b * x)
params, param_cov = curve_fit(func, x, y)
print(params)
print(param_cov)
ans = (params[0]*(np.exp(params[1]*x)))
plt.plot(x, y, 'o', color ='red', label ="data")
plt.plot(x, ans, '--', color ='blue', label ="optimized data")
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment