The ScatterPlot component creates interactive scatter plots from pandas DataFrames.
Basic usage
import gradio as gr
import pandas as pd
df = pd.DataFrame({
"x": [1, 2, 3, 4, 5],
"y": [2, 4, 3, 5, 6]
})
gr.ScatterPlot(
value=df,
x="x",
y="y"
)
Constructor
value
pd.DataFrame | Callable | None
default:"None"
Pandas DataFrame containing the data
Column name for y-axis (must be numeric)
Column name for color grouping
color_map
dict[str, str] | None
default:"None"
Mapping of categories to colors
Events
- select - Triggered when point is selected
- double_click - Triggered on double click
Example
import gradio as gr
import pandas as pd
import numpy as np
def create_scatter():
np.random.seed(42)
df = pd.DataFrame({
"height": np.random.normal(170, 10, 100),
"weight": np.random.normal(70, 15, 100),
"gender": np.random.choice(["M", "F"], 100)
})
return df
gr.ScatterPlot(
value=create_scatter(),
x="height",
y="weight",
color="gender",
title="Height vs Weight",
color_map={"M": "#3B82F6", "F": "#EC4899"}
)