Skip to content

[BUG]: Unable to write_image with datetime64 axis in recent versions #7585

@EuanRichard

Description

@EuanRichard

Description

With plotly==6.3.1 and kaleido==1.1.0, I wasn't able to add shapes (add_vline, add_shape, ...) to a time-axis line plot and then use write_image. The shapes wouldn't appear on the image, or would have a wildly incorrect x-axis location.

Steps to reproduce

import pandas as pd
import plotly.express as px

x = ['2001-01-01', '2001-01-02', '2001-01-03']
y = [0, 3, 1]

x = pd.to_datetime(x) # Now Pandas Index of NumPy datetime64[ns]

fig = px.line(x=x, y=y)

fig.add_vline('2001-01-02')
fig.add_shape(type='rect', x0='2001-01-01', x1='2001-01-01 12:00:00', y0=0, y1=1)

fig.show() or fig.write_html() works fine:
Image

fig.write_image() with .png, .svg etc. does not:
Image

Notes

  • Downgrading to plotly==6.0 and kaleido==0.2.1 will cause write_image to work OK, so maybe a recent change.
  • Removing the line pd.to_datetime(x) will also "fix" the issue, so maybe related to handling of datetime64[ns] inside write_image (as can be seen in the lower plot, it doesn't seem to recognise the x-axis as a time axis)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions