SpaceSloth
SpaceSloth

Reputation: 89

Plotly axis shows Datetime as numbers instead of dates

I am plotting my Dataframe using Plotly but for some reason, my Datetime values gets converted numbers instead of getting displayed as letters

    fig.add_trace(go.Scatter(x=df2plt["PyDate"].values,
                         y=df2plt["Data"].values))

enter image description here

Upvotes: 0

Views: 1407

Answers (1)

Renaud
Renaud

Reputation: 2819

If df2plt["PyDate"] is already in datetime format:

fig.add_trace(go.Scatter(x=df2plt["PyDate"],
                     y=df2plt["Data"].values))

Else:

fig.add_trace(go.Scatter(x=pd.to_datetime(df2plt["PyDate"]) ,
                     y=df2plt["Data"].values)) 

You can change the display with the variable format:

*format : string, default None strftime to parse time, eg “%d/%m/%Y”, note that “%f” will parse all the way up to nanoseconds. See strftime documentation for more information on choices: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior *

Upvotes: 1

Related Questions