Skip to content

feature request: make graph_objects also dataframe agnostic #5166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Noghpu opened this issue May 5, 2025 · 0 comments
Open

feature request: make graph_objects also dataframe agnostic #5166

Noghpu opened this issue May 5, 2025 · 0 comments

Comments

@Noghpu
Copy link

Noghpu commented May 5, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant