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

Pandas DateTimeIndex x-axis no longer date

Open miohtama opened this issue 7 months ago • 0 comments

After upgrading to Plotly 6.x x-axis as DateTimeIndex is not automatically detected as a time x-axis. Instead, it looks like it is UNIX epoch seconds or nanoseconds. Now on Plotly 6.1.2.

Image

This worked in Plotly 5.x.

As a workaround one can manually cast DateTimeIndex to a list of Python datetime instances to fix the issue, but this is a bit cumbersome.

Works:

    index = df.index.to_pydatetime().tolist()

    # Price chart (top subplot)
    fig.add_trace({
        "x": index,
        "y": df["mark_price"],
        "type": "scatter",
        "mode": "lines",
        "name": "Price",
        "line": {"width": 2},
        "showlegend": False
    }, row=1, col=1)

Does not work and produced the screenshot above:

    # Price chart (top subplot)
    fig.add_trace({
        "x": df.index,
        "y": df["mark_price"],
        "type": "scatter",
        "mode": "lines",
        "name": "Price",
        "line": {"width": 2},
        "showlegend": False
    }, row=1, col=1)

miohtama avatar Jun 14 '25 20:06 miohtama