Hi,
I am trying to add a vertical line using the (.add_vline) method. However, the line is consistently being plotted in the middle of the chart despite the (x) variable value does not place the line in the middle of the chart. Here is the full code to plot my chart:
Plot the time series data and two-week rolling average using Plotly
fig = px.line(filtered_df, x=‘Time’, y=parameter, title=‘Time Series Plot with Four-Week Rolling Average’)
fig.add_scatter(x=time, y=avg_param, name=‘Four-Week Average’, line=dict(color=‘red’, dash=‘dash’))
fig.update_traces(line=dict(shape=‘spline’))
Add vertical lines for start_date and end_date
fig.add_vline(x = inc_time, line_color= ‘black’, line_dash = ‘dash’)
Update the layout to adjust the title position
fig.update_layout(
title=dict(text='Time Series Plot with Four-Week Rolling Average: ’ + parameter + ’ - ’ + facility, x=0.5, y=0.95),
xaxis=dict(title=‘Time’),
yaxis=dict(title=parameter)
)fig.show()
Note, here in my case, inc_time is equal to Timestamp(‘2022-01-21 15:45:00’), however, as shown in the chart below, the vertical line is drawn at 17:00.
What am I missing?
Hossam