Skip to content

Commit

Permalink
added logarithmic scale
Browse files Browse the repository at this point in the history
  • Loading branch information
patalanov committed May 9, 2020
1 parent 693051e commit 71d9765
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion covid19.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# APP
def main():
# Add a title
st.title('COVID19 predictions')
st.title('COVID-19 predictions')
# get preliminary data
with st.spinner('Global map is being updated...'):
time.sleep(3)
Expand Down Expand Up @@ -107,6 +107,8 @@ def main():
value=100)
#show timeline
first_day, df = timeline_of_cases_and_deaths(country, notification_percentual)
# show also the data using a logarithic scale
plot_logarithmic(country, notification_percentual)
# plot daily increase of cases
plot_daily_increase(select, first_day, df)
# A brief theoretical explanation
Expand Down Expand Up @@ -303,6 +305,32 @@ def timeline_of_cases_and_deaths(country, notification_percentual):
return first_day, df


def plot_logarithmic(country, notification_percentual):
plt.rcParams["font.family"] = "Times New Roman"
plt.rcParams["font.size"] = "8"
plt.rcParams['axes.grid'] = True
# filter target data
cases = country[0]["timelines"]["confirmed"]["timeline"]
#print ('CASES', cases, 'ITEMS', cases.items())
deaths = country[0]["timelines"]["deaths"]["timeline"]
# create dataframes for cases
cases_df = pd.DataFrame(list(cases.items()),
columns=['day', 'cases'])
# apply subnotification percentage
# if none was entered, it is == 1
cases_df.cases = cases_df.cases*100/notification_percentual
#a = [pow(10, i) for i in range(10)]
fig = plt.figure()
ax = fig.add_subplot(2, 1, 1)

line, = ax.plot(cases_df.cases, color='blue', lw=1)
ax.set_yscale('log')
pylab.show()
st.write('**Logarithmic scale**')
st.write('This scale makes it possible to fit a large or widespread set of results onto a graph that might otherwise not fit in a linear way. A logarithmic graph can also help make it clear if the apparent evening-out of the curve started to change. While a linear curve would keep on pushing ever higher regardless, the logarithmic graph would highlight any substantial changes to the trend – whether upward or downward. It’s an approach that is often preferred when there are huge numbers involved and a linear scale would just produce a dramatic-looking exponential curve.')
st.pyplot()


def plot_daily_increase(select, first_day, df):
dfG = df.copy()
dfG['cases_diff'] = dfG.diff()['cases']
Expand Down

0 comments on commit 71d9765

Please sign in to comment.