def deceased_output(totalcases): date = Cumulative_graph[Cumulative_graph['State'] == totalcases]['Date'] deceased = Cumulative_graph[Cumulative_graph['State'] == totalcases]['Deceased'] fig = go.Figure( go.Line(x=date, y=deceased, marker=dict(color='#798189'), line=dict(width=3), mode='lines+markers', text='<b>Date</b>: ' + date.astype(str) + '<br>' + '<b>Deceased</b>: ' + [f'{x:,.0f}' for x in deceased] + '<br>', hoverinfo='text')) fig.update_xaxes(title=None, showgrid=False, fixedrange=True, linecolor='#798189', title_font_color='#798189', linewidth=2, ticks='outside', tickfont=dict(family='Arial', size=12, color='#798189')) fig.update_yaxes(side="right", showgrid=False, fixedrange=True, linecolor='#798189', linewidth=2, ticks='outside', tickfont=dict(family='Arial', size=12, color='#798189')) fig.update_layout( hoverlabel_font_color='#ffffff', plot_bgcolor='#f6f6f7', hovermode='x', margin=dict(t=15, b=15, r=15, l=15), paper_bgcolor='#f6f6f7', ) fig.update_traces(fill="tonexty", selector=dict(type='scatter')) fig.add_annotation(text="Death", xref="paper", yref="paper", x=0.01, y=0.99, showarrow=False, font=dict(size=13, )) return fig
def add_datetime_column(df): """Add full datetime column to MCS L2 dataframe. Using get_time and get_date helpers, combine them into a full datetime column and add it to the incoming dataframe. Set index to the new datetime column. Parameters ---------- df : pd.DataFrame A MCS dataframe that has a `Date` and a `Time` column in the formats yyyymmdd (int) for the date and seconds of the day for time, respectively. Returns ------- Nothing, new column is added to the incoming dataframe and then made into the index. """ time = df.Time.map(get_time) date = df.Date.map(get_date) df["datetime"] = pd.to_datetime(date.astype(str) + " " + time) df.set_index("datetime", inplace=True)
def cleanCreationDate(date): return (date.astype('datetime64[D]').view('int64') - 4) % 7
temp = datetime.strptime(aRow, '%Y-%m') x1.append(temp) temp = [] y = np.array(y, dtype=float) years = mdates.YearLocator() # every year months = mdates.MonthLocator() # every month yearsFmt = mdates.DateFormatter('%Y') date = [] for aItem in x1: # print aItem np.datetime64(aItem) date.append(aItem) date = np.array(date, dtype='datetime64[D]') date = date.astype('O') N3p4Dates = copy.deepcopy(date) y = np.array(y, dtype='float') # print date fig, ax = plt.subplots(figsize=(12, 6)) ax.plot(date, y, label='ONI') # format the ticks ax.xaxis.set_major_locator(years) ax.xaxis.set_major_formatter(yearsFmt) # ax.xaxis.set_minor_locator(months) # myFmt = mdates.DateFormatter('%m') # ax.xaxis.set_minor_formatter(myFmt) import datetime