PlatonB
1
I need to plot:
- X grid lines corresponding to every datetime value from dataframe column;
- X grid lines by months.
There is no problem with the first point:
fig = px.scatter(src_df, x='date', y='never_mind')
fig.update_layout({'xaxis': {'tickvals': src_df['date']}})
The data for the lines by month I generate as follows:
pd.date_range(src_df.iloc[0]['date'], src_df.iloc[-1]['date'], freq='MS').to_frame(index=False)
How do I output both sets of X grid lines?
Sketch of the desired result:
I found a new Plotly feature - vertical lines. So now what I had in mind partially works.
mon_starts = pd.date_range(src_df.iloc[0]['date'], src_df.iloc[-1]['date'], freq='MS')
for mon_start in mon_starts:
fig.add_vline(x=mon_start, line_width=1, line_dash='dash')
But how do I make labels to these vertical lines? Adding annotation_text=mon_start
argument causes an error:
TypeError: Addition/subtraction of integers and integer-arrays with Timestamp is no longer supported.