I hereby claim:
- I am perishleaf on github.
- I am junye (https://keybase.io/junye) on keybase.
- I have a public key ASDUVsqBw-d5tgjaEVn6kFclkWH4Kgb8hQe3hlTgZ70n8Qo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
import dash | |
import dash_core_components as dcc | |
import dash_html_components as html | |
from dash.dependencies import Input, Output | |
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] | |
app = dash.Dash(__name__, external_stylesheets=external_stylesheets) | |
app.layout = html.Div([ |
# 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', |
# Add coordinates for each area in the list for the latest table sheet | |
# As there are limit for free account, we only call coordinates for the latest table sheet | |
from opencage.geocoder import OpenCageGeocode | |
key = 'Your key number' # get api key from: https://opencagedata.com | |
geocoder = OpenCageGeocode(key) | |
list_lat = [] # create empty lists | |
list_long = [] | |
for index, row in dfs[keyList[0]].iterrows(): # iterate over rows in dataframe | |
City = row['Province/State'] |
# Import xlsx file and store each sheet in to a df list | |
xl_file = pd.ExcelFile('./data.xlsx',) | |
dfs = {sheet_name: xl_file.parse(sheet_name) | |
for sheet_name in xl_file.sheet_names} | |
# Data from each sheet can be accessed via key | |
keyList = list(dfs.keys()) | |
# Data cleansing |
for i, city in enumerate(cityList): | |
ax = fig.add_subplot(gs[i+2, 0:9], ylim=(-30, 30)) | |
df_tmp = df.loc[df['City'] == city] | |
# color scheme | |
colors = cm.RdYlBu_r(df_tmp.max_tmp_day / max(df_tmp.max_tmp_day)) | |
ax.bar(df_tmp.Date, df_tmp.max_tmp_day - mean_temp, label='_1', color=colors, | |
width=0.7, align="edge") | |
# annotation for highest temp. |
# Set canvas background color the same as axes | |
plt.rc('figure', facecolor='w') | |
# Arrange city based on latitude | |
cityList = ['hobart', 'melbourne', 'canberra', 'adelaide', 'sydney', 'perth', 'brisbane', 'darwin'] | |
# set constrianed_layout as True to avoid axes overlap | |
fig = plt.figure(figsize=(10,12), dpi=300, constrained_layout=True) | |
# Use GridSpec for customising layout |
def draw_linechart(Num_Year): | |
''' | |
This is the function to make a plot | |
''' | |
# since many figures will be generated for animation, old axes need to be cleared before drawing new axes | |
ax.clear() | |
ax2.clear() | |
# select data till the indicated year | |
df_tmp=df_sydney.loc[df_sydney['Year'] <= Num_Year] |
# set up plot style as tron legancy | |
from matplotlib import cycler | |
colors = cycler('color', | |
['#fc280f', '#5fdcff', '#f4ba26', '#85c54c', '#c6d7e0']) # colors for artists will be cycled from this list by default | |
plt.rc('figure', facecolor='#222222') # facecolor is background colour | |
plt.rc('axes', facecolor='#222222', edgecolor='#222222', | |
axisbelow=True, grid=True, prop_cycle=colors) # "axisbelow" set axis ticks and gridlines are below all artists | |
plt.rc('grid', color='#e3e3e3', linestyle='solid') | |
plt.rc('xtick', direction='in', color='#e3e3e3') | |
plt.rc('ytick', direction='in', color='#e3e3e3') |
import matplotlib.pyplot as plt | |
import numpy as np | |
# set up a seed to make the random result reproducible | |
np.random.seed(seed=666) | |
# create some data to use for the plot | |
dt = 0.001 | |
t = np.arange(0.0, 10.0, dt) | |
r = np.exp(-t[:1000]/0.05) # impulse response |