I am graphing a few df and I sorted them before graphing, but in the graph the x axis is not in order. Shown in the pic below
I sorted the df and converted the x axis to datetime.
Here is my code.
df_login_s[‘mininterval’] =pd.to_datetime(df_login_s[‘mininterval’])
df_login_f[‘mininterval’] =pd.to_datetime(df_login_f[‘mininterval’])
df_login_f_p[‘mininterval’]= pd.to_datetime(df_login_f_p[df_login_f_p[‘tenant’]==tenant][‘mininterval’],errors=‘coerce’)
df_login_s_p[‘mininterval’]= pd.to_datetime(df_login_s_p[df_login_s_p[‘tenant’]==tenant][‘mininterval’],errors=‘coerce’)
fig = make_subplots(rows=2, cols=1,
shared_xaxes=True,
vertical_spacing=0.02)
fig.add_trace(go.Scatter(x=df_login_s[df_login_s['tenant']==tenant]['mininterval'].dt.time.sort_values(),
y=df_login_s[df_login_s['tenant']==tenant]['success_ct'],
mode='lines',
name='current_outage_success'),
row=1, col=1)
fig.add_trace(go.Scatter(x=df_login_s_p[df_login_s_p['tenant']==tenant]['mininterval']
, y=df_login_s_p[df_login_s_p['tenant']==tenant]['success_avg'],
mode='markers',
name='prior_weeks_success'),
row=1, col=1)
fig.add_trace(go.Scatter(x=df_login_f[df_login_f['tenant']==tenant]['mininterval'].dt.time.sort_values(),
y=df_login_f[df_login_f['tenant']==tenant]['failure_ct'],
mode='markers',
name='current_outage_fail'),
row=2, col=1)
fig.add_trace(go.Scatter(x=df_login_f_p[df_login_f_p['tenant']==tenant]['mininterval']
, y=df_login_f_p[df_login_f_p['tenant']==tenant]['fail_avg'],
mode='markers',
name='prior_weeks_fail'),
row=2, col=1)
fig.update_xaxes(
title_text = "Time (UTC)", row=2,col=1)
fig.update_yaxes(
title_text = "Success Login",
title_standoff = 25,row=1, col=1)
fig.update_yaxes(
title_text = "Success Login",
title_standoff = 25,row=1, col=1)
fig.update_yaxes(
title_text = "Fail Login",
title_standoff = 25,row=2, col=1)
fig.update_yaxes(
title_text = "Fail Login",
title_standoff = 25,row=2, col=1)
fig.update_layout(height=800, width=1000,
title="{},{}".format(tenant,single_date))
fig.show()