plotly / plotly/plotly.py

feature request: make graph_objects also dataframe agnostic

Open
#5,166 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

I was wondering, since narwhals was such a success in the plotly express api, whether the graph_objects api could get the same treatment. For the few trace types I tried (Scatter, Bar), arguments such as x, y, marker_color etc., accept tuple, list, numpy array, or pandas Series.

It would be great to be able to pass arrow or polars series as well, via narwhals, though I have no idea how feasible that would really be.

Desired outcome would be something like this:

"""
Fresh environment
>>> uv init
>>> uv add plotly polars
"""

import plotly.graph_objects as go
import polars as pl

df = pl.DataFrame({"x": [0, 1, 2, 3, 4], "y": [0, 1, 4, 9, 16]})

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

Currently one has to either transform to a list, pandas series, or if numpy is installed, there is some implicit transformation, which allows to pass polars series directly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided polars example through the graph_objects API, focusing on go.Figure.add_trace with Scatter and Bar. Inspect how their x, y, and marker_color arguments currently handle lists, NumPy arrays, and pandas Series. Done means the relevant graph_objects trace arguments accept polars and Arrow series through narwhals without requiring conversion.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.