import gradio as gr
import pandas as pd
import numpy as np
simple = pd.DataFrame(np.array(
[
["A", 28],
["B", 55],
["C", 43],
["D", 91],
["E", 81],
["F", 53],
["G", 19],
["H", 87],
["I", 52],
]
), columns=["item", "inventory"])
with gr.Blocks() as demo:
gr.BarPlot(
value=simple,
x="item",
y="inventory",
title="Simple Bar Plot",
container=True,
width=400
)
demo.launch()
pandas
Description
Creates a bar plot component to display data from a pandas DataFrame.
Behavior
As input component: The data to display in a line plot.
Your function should accept one of these types:
defpredict(
value: AltairPlotData
)...
As output component: Expects a pandas DataFrame containing the data to display in the line plot. The DataFrame should contain at least two columns, one for the x-axis (corresponding to this component's x argument) and one for the y-axis (corresponding to y).
Your function should return one of these types:
defpredict(···)-> pd.DataFrame |None...return value
Initialization
Parameters
Shortcuts
Class
Interface String Shortcut
Initialization
gradio.BarPlot
"barplot"
Uses default values
Demos
import gradio as gr
from scatter_plot_demo import scatter_plots
from line_plot_demo import line_plots
from bar_plot_demo import bar_plots
with gr.Blocks() as demo:
with gr.Tabs():
with gr.TabItem("Line Plot"):
line_plots.render()
with gr.TabItem("Scatter Plot"):
scatter_plots.render()
with gr.TabItem("Bar Plot"):
bar_plots.render()
if __name__ == "__main__":
demo.launch()
Event Listeners
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a
function is called.
Supported Event Listeners
The BarPlot
component supports the following event listeners. Each event listener takes the
same parameters, which are listed in the
Event Parameters table below.
Listener
Description
BarPlot.select(fn, ···)
Event listener for when the user selects or deselects the NativePlot. Uses event data gradio.SelectData to carry value referring to the label of the NativePlot, and selected to refer to state of the NativePlot. See EventData documentation on how to use this event data