Hi,
I would like to use label aliases for timestamp data without editing the raw input data.
The idea behind this is that we are not interested in the exact date, but rather day 1, day 2, day 3 etc.
My idea is to create a dict with the original dates and the new dates shifted to January 1st (it will always be less than 100 days) and then plot only the day of the timestamp date.
In the end it should show day 1, day 2, day 3 instead of the date (as shown in red). converting the dates completely to str will make the nice daywise date spacing go away and was not really an option.
Can you help me how to make this work? are the timestamps internally converted to str format and I can access them that way?
Thanks
minimal example:
import pandas as pd
import plotly.graph_objects as go
import plotly
### sample data
data = {'value': [10, 20, 15, 25, 30, 10, 20, 15, 25, 30]}
dates = pd.date_range('2020-05-06', periods=10, freq='6H')
df = pd.DataFrame(data, index=dates)
### original figure with days in correct format
fig = go.Figure()
fig.add_trace(go.Scatter(x=df.index, y=df['value'], mode='lines+markers'))
fig.update_xaxes(tickformat="%H:%M\nDay %_j")
fig.show()
### figure with days starting at day 1
dates_new = dates.shift(-dates.dayofyear[0]+1, freq='D')
pairwise_dict = {key: value for key, value in zip(dates, dates_new)}
fig.update_xaxes(
labelalias=pairwise_dict,
tickformat="%H:%M\nDay %_j"
)
fig.show()
### TypeError: keys must be str, int, float, bool or None, not Timestamp