plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Plotly Express not displaying datetime

Open Joshua-Powell-Lambda opened this issue 10 months ago • 2 comments

the x-axis of my graph is displaying as the ns value of the timestamp, 1715000000000000000, instead of the corresponding readable timestamp.

The code is

        fig = go.Figure()
        local_df["reservation_start_week_utc"] = pd.to_datetime(local_df[
            "reservation_start_week_utc"
        ].apply(lambda x: pd.Timestamp(x).to_pydatetime()))

        fig.add_trace(
            go.Scatter(
                x=local_df["reservation_start_week_utc"],
                y=local_df["weighted_average_price"],
...

the datatype of the column that populates my x-axis is datetime64[ns, UTC] I tried casting to different types, and also several different format settings on the plot. I couldnt get it to work. Rolling back plotly immediately fixed the bug

python versions used 3.13 and 3.10 no difference.

rolling back from plotly 6.0.1 to 5.24.1 fixed the formatting issue

Joshua-Powell-Lambda avatar Mar 19 '25 22:03 Joshua-Powell-Lambda

I see the same issue and is also back to version 5 for now...

TermeHansen avatar Apr 04 '25 09:04 TermeHansen

Hi @Joshua-Powell-Lambda , could you let me know whether you still experience this issue with plotly==6.4.0?

I can't completely recreate your example since I don't know the contents of local_df, but I wrote the following as a best guess:

import pandas as pd
import plotly.graph_objs as go

local_df = pd.DataFrame(
    {
        "reservation_start_week_utc": ["2024-10-07", "2024-10-14", "2024-10-21"],
        "weighted_average_price": [100, 150, 120],
    }
)

local_df["reservation_start_week_utc"] = pd.to_datetime(
    local_df["reservation_start_week_utc"].apply(
        lambda x: pd.Timestamp(x).to_pydatetime()
    )
)

fig = go.Figure()
fig.add_trace(
    go.Scatter(
        x=local_df["reservation_start_week_utc"],
        y=local_df["weighted_average_price"],
    )
)
fig.show()

Running the above code with plotly==6.4.0 gives me the following plot:

Image

which looks correct.

Let me know if you still experience the issue with the latest Plotly. And if so, if you can provide a complete code example to reproduce the issue, that would be very helpful. I am investigating a similar issue right now (#5355) so I would like to cover this issue with the fix as well, if it is still a problem. Thanks!

emilykl avatar Nov 10 '25 23:11 emilykl