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

feature request: make graph_objects also dataframe agnostic

Open Noghpu opened this issue 8 months ago • 1 comments

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.

Noghpu avatar May 05 '25 20:05 Noghpu

@Noghpu this would be very useful, but we're unlikely to get to it any time soon - if you'd like to open a PR, I'd be happy to prioritize review. thanks - @gvwilson

gvwilson avatar May 08 '25 18:05 gvwilson