gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
32.45k stars 2.43k forks source link

What plot components should we implement? #2463

Closed freddyaboulton closed 10 months ago

freddyaboulton commented 1 year ago

Is your feature request related to a problem? Please describe.
Gradio developers can already create cool visualizations with the Plot component. See this interactive map and this bike share dashboard (https://gradio.app/connecting_to_a_database/).

This is great but it has some drawbacks:

Describe the solution you'd like

Implement components for common plot types. gr.BarPlot, gr.LinePlot etc.

These components should just take a dataframe or dict and some additional parameters to configure the plot, e.g. gr.BarPlot(df, x="category", y="spent", x_label="Spending Category").

Rather than delegating to an external library to generate the plot, the front-end will plot the data. This will ensure consistent theming with the rest of the app and will make it easier to apply custom themes to plots once we do theming.

We can also do something like gr.Barplot(..., backend="plotly") if the developer wants to use plotly. gr.Plot should still work as expected and handle plotly or matplotlib plots.

Additional context
Add any other context or screenshots about the feature request here.

freddyaboulton commented 1 year ago

A proposal of possible plot types to support:

General plots

Statistical more specific plots:

My current thinking is that some more specific visualizations can be implemented with the primitives listed above by extending their api slightly. We can also add first-class components for these:

Area Chart

image

Grouped and Stacked BarCharts

image image

Layered Histogram

image
abidlabs commented 1 year ago

Pinned the issue -- would appreciate feedback from Gradio users on other plot types they'd like to see!

radames commented 1 year ago

hi @freddyaboulton, I'd also tag @severo for more Data Vis ideas. Are these plots powered by matplotlib or plotly? Not sure if this is the case now, but with custom components in the future, I'd like to try something like Observablehq Plot to provide a grammar of composable Marks, that maybe can be build direct from python.

freddyaboulton commented 1 year ago

Thanks for the comment @radames !

Right now, the plan is to use altair which is a python front-end for vega. Vega supports a "grammar of graphics" similar to observable's Plot from what I can tell.

The "gradio plots", like gr.ScatterPlot and gr.LinePlot, etc will just be convenient wrappers over altair (and thus vega) with the added benefit that they will play play better with the current gradio theme (fonts, colors etc).

For custom visualizations, developers will be able to use altair to display their viz in a standard Plot component. Once the theming work is done, my hope is that the current theme is exposed on the python side as well so that users can make their custom visualizations match the rest of the app.

If developers prefer to write their charting code in js, that will have wait for custom components. But again they should be able to make them match the rest of the app by leveraging the current theme.

Let me know if this meshes with your thoughts as well!

severo commented 1 year ago

What level of abstraction would you like for the library? The following article and figures can help define it: https://nightingaledvs.com/navigating-the-wide-world-of-data-visualization-libraries/. Once you have chosen the right level of abstraction, you also have a list of (JS) libraries that implement it, so it's easier to get inspiration about the list of components to create.

Capture d’écran 2022-12-27 à 11 32 50
pngwn commented 1 year ago

Going to unpin as engagement has dropped off.

abidlabs commented 1 year ago

Let's go ahead and close if we are not planning on adding any more Plot components soon @freddyaboulton?

sri-awadh commented 1 year ago

could we add functionality to interact with gradio.components.Plot. For example if plotly.graph_objs.FigureWidget is used for displaying graph through gradio.components.Plot could we get selected-graph-points through plotly's 'Box select' functionality .

sri-awadh commented 1 year ago

is there any event listener for gradio.components.Plot? if no. please consider it for implementation.

jsirait commented 10 months ago

Would be interested to see BoxPlot component implemented :)

freddyaboulton commented 10 months ago

Going to close. I think new plots can be implemented via custom components! https://www.gradio.app/guides/custom-components-in-five-minutes