Created
February 2, 2020 09:06
-
-
Save Perishleaf/3f2ccfbe165f4d959385a56c863ef15c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Line plot for confirmed cases | |
# Set up tick scale based on confirmed case number | |
tickList = list(np.arange(0, df_confirmed['Mainland China'].max()+1000, 1000)) | |
# Create empty figure canvas | |
fig_confirmed = go.Figure() | |
# Add trace to the figure | |
fig_confirmed.add_trace(go.Scatter(x=df_confirmed['Date']+timedelta(hours=16), y=df_confirmed['Mainland China'], | |
mode='lines+markers', | |
name='Mainland China', | |
line=dict(color='#921113', width=2), | |
marker=dict(size=8), | |
text=[datetime.strftime(d+timedelta(hours=16), '%b %d %Y %H:%M AEDT') for d in df_confirmed['Date']], | |
hovertemplate='<b>%{text}</b><br></br>'+ | |
'Mainland China confirmed<br>'+ | |
'%{y} cases<br>'+ | |
'<extra></extra>')) | |
fig_confirmed.add_trace(go.Scatter(x=df_confirmed['Date']+timedelta(hours=16), y=df_confirmed['Other locations'], | |
mode='lines+markers', | |
name='Other Region', | |
line=dict(color='#eb5254', width=2), | |
marker=dict(size=8), | |
text=[datetime.strftime(d+timedelta(hours=16), '%b %d %Y %H:%M AEDT') for d in df_confirmed['Date']], | |
hovertemplate='<b>%{text}</b><br></br>'+ | |
'Other region confirmed<br>'+ | |
'%{y} cases<br>'+ | |
'<extra></extra>')) | |
# Customise layout | |
fig_confirmed.update_layout( | |
title=dict( | |
text="<b>Confirmed Cases Timeline<b>", | |
y=0.96, x=0.5, xanchor='center', yanchor='top', | |
font=dict(size=20, color="#ffffff", family="Playfair Display") | |
), | |
margin=go.layout.Margin( | |
l=5, | |
r=10, | |
b=10, | |
t=50, | |
pad=0 | |
), | |
yaxis=dict( | |
showline=True, linecolor='#272e3e', | |
zeroline=False, | |
gridcolor='#272e3e', | |
gridwidth = .1, | |
tickmode='array', | |
# Set tick range based on the maximum number | |
tickvals=tickList, | |
# Set tick label accordingly | |
ticktext=["{:.0f}k".format(i/1000) for i in tickList] | |
), | |
yaxis_title="Total Confirmed Case Number", | |
xaxis=dict( | |
showline=True, linecolor='#272e3e', | |
gridcolor='#272e3e', | |
gridwidth = .1, | |
zeroline=False | |
), | |
xaxis_tickformat='%b %d', | |
hovermode = 'x', | |
legend_orientation="h", | |
plot_bgcolor='#151920', | |
paper_bgcolor='#272e3e', | |
font=dict(color='#ffffff') | |
) | |
fig_confirmed.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment