The BarPlot component creates interactive bar charts from pandas DataFrames using Gradio’s native plotting.
Basic usage
import gradio as gr
import pandas as pd
df = pd.DataFrame({
"category": ["A", "B", "C"],
"value": [10, 25, 15]
})
gr.BarPlot(
value=df,
x="category",
y="value"
)
Constructor
value
pd.DataFrame | Callable | None
default:"None"
Pandas DataFrame containing the data
Column name for x-axis (can be numeric, datetime, or string)
Column name for y-axis (must be numeric)
Column name for color grouping (must be string/category)
X-axis title (defaults to column name)
Y-axis title (defaults to column name)
color_map
dict[str, str] | None
default:"None"
Mapping of series names to colors (e.g., {"A": "red", "B": "#00FF00"})
y_lim
list[float | None]
default:"None"
Y-axis limits as [min, max]. Use None to auto-scale one end
Events
- select - Triggered when bar is selected
- double_click - Triggered on double click
Example
import gradio as gr
import pandas as pd
def create_sales_chart():
df = pd.DataFrame({
"Product": ["A", "B", "C", "D"],
"Sales": [120, 250, 180, 90],
"Region": ["North", "North", "South", "South"]
})
return df
with gr.Blocks() as demo:
plot = gr.BarPlot(
value=create_sales_chart(),
x="Product",
y="Sales",
color="Region",
title="Sales by Product",
color_map={"North": "#FF6B6B", "South": "#4ECDC4"},
height=400
)
demo.launch()