Hello,
I’m plotting quarterly observations. Dates stored as <class ‘numpy.int64’> are converted pd.to_datetime to get datetime such as Timestamp(‘2022-12-31 00:00:00’) for the last day of Q4 2022
When plotting, dash shows Jan 2023 rather than Dec 2022
Is there a way to show Dec 2022, or, even better, Q4 '22 ', without modifying the data?
I tried tickformat=‘%q %y’
but it still shows 1 23 rather than 4 22 How to change this ? My datetime clearly is 2022-12-31, why does dash considers that as 2023-01-01 ?
Basically just plot 1 point with a timestamp as x and random value as y:
import plotly.graph_objs as go
import pandas as pd
import plotly.io as pio
go.Figure(
data=[
go.Scatter(
x=pd.to_datetime([20221231, 20230331], format="%Y%m%d"),
y=[10, 20]
)
],
layout=go.Layout(template=pio.templates["plotly"])
).show()
I had already boiled down the problem to the minimum, textually
I also notice that the labelson the xaxis don’t exactly appear below the datapoint. The xaxis being a datetime, it is labelled at “random interval”. Seems to be the cause of the issue here; I would like the tick label to appear online where the x value of the data point is also a tick. In other word, that my ticks become the quarters end.
haha yes, that was the solution I was woriking on, right now, I found the hint in the last sentence of dtick formatting: " To set ticks on the 15th of every third month, set tick0 to “2000-01-15” and dtick to “M3”. To set ticks every 4 years, set dtick to “M48"”
Thanks for the link to the examples. Might be useful for the next charts.