Skip to content

plotly 6.3.0 does not work with numpy datetime #5355

@StageTired

Description

@StageTired

I upgraded my requirements from plotly==5.9.0 to plotly==6.3.0 and observed a regression. Markers on the plot disappeared without any error.

Simply put, my code takes a figure as input and plots a dot at the end of each line. Simple reproducible example:

import numpy as np
import pandas as pd
import plotly.graph_objs as pgo
import plotly.subplots

np.random.seed(42)

# random data
dates = pd.date_range(start="2025-01-01", periods=3, freq="D")
data = np.random.randn(3, 1)
df = pd.DataFrame(data, index=dates, columns=["value"])

# this is plotted elsewhere
fig = plotly.subplots.make_subplots()

for column in df.columns:
    trace = pgo.Scatter(
        x=df.index,
        y=df[column],
        mode="lines",
    )

    fig.add_trace(trace)

# take the figure and
# render last point of each line using fig.data
for i, trace in enumerate(fig.data):
    input_x = trace.x[-1]
    input_y = trace.y[-1]
    print("Input x:", input_x, type(input_x))
    print("Input y:", input_y, type(input_y))

    fig.add_scatter(
        x=(input_x,),
        y=(input_y,),
        mode="markers+text",
    )
    print(f"Plotted x value:", fig.data[-1].x)

fig.show()

If I run this with different plotly versions I get different type for the timestamp:

Image

With plotly<6, the figure looks like this

Image With plotly>=6, it looks like this Image

I am aware that I can convert numpy datetime back to datetime.datetime to fix my problem but why does plotly treat numpy datetime as a unix timestamp? It's not being converted to an actual date and there is no error either.
Simply put I would expect x axis to be a date and not an impossibly large number:

import numpy as np
import plotly.subplots

fig = plotly.subplots.make_subplots()

x = np.datetime64('2025-09-26T01:00:00.000000000')
y = 1.23

fig.add_scatter(
    x=(x,),
    y=(y,),
    mode="markers+text",
)
print(f"Plotted x value:", fig.data[-1].x)

fig.show()
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1needed for current cyclebugsomething brokenregressionthis used to work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions