Export to png ; Export to html/png requires explicit range specified for dates (pd.DateTimeIndex)

Offen
#396 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@ayjayt arbeitet bereits daran.

Seit 26.8.2025.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

bug P2
kaleido==1.0.0
plotly==6.3.0

The Scatter plot below using pandas dates look fine on the Notebook, but

  1. When exporting to html and png, the range needs to be set explicitly range=[dates.min(), dates.max()]. Otherwise the default starts from Jan 2000.
  2. For png export, after the explicit fix above, the x-axis range is corrected, but the line disappeared.

There's a workaround which is to convert the dates to str for the x data values first x=dates.strftime("%Y-%m-%d") but this is a gotcha.

    # Sample time series data
    dates = pd.date_range(start="2024-01-01", periods=30, freq="D")
    values = [20 + i + (i % 7) * 3 for i in range(30)]  # Trending data with weekly pattern

    # Create line chart with Graph Objects
    fig = go.Figure()

    fig.add_trace(
        go.Scatter(
            x=dates,  # Plotly handles pandas DatetimeIndex directly
            y=values,
            mode="lines+markers",
            name="Daily Values",
            line=dict(color="blue", width=2),
            marker=dict(size=4),
        )
    )

    # Update layout with explicit date range
    fig.update_layout(
        title="Basic Line Chart - Graph Objects API",
        xaxis_title="Date",
        yaxis_title="Value",
        width=800,
        height=600,
        showlegend=True,
        xaxis=dict(
            type="date",
            # Explicitly set the date range for html and image export
            range=[dates.min(), dates.max()]
        ),
    )

    # Save as HTML and PNG
    fig.write_html(data_dir / "01_basic_line.html")
    fig.write_image(data_dir / "01_basic_line.png")
Vorherrschende Sprache
Python
Sterne
504
Forks
65
Ø Merge
6 T. 9 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus plotly/kaleido

Alle Issues in plotly/kaleido

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.