Introducing Gradio Clients

Watch

New to Gradio? Start here: Getting Started

See the Release History

LinePlot

gradio.LinePlot(ยทยทยท)
import gradio as gr import pandas as pd import numpy as np simple = pd.DataFrame(np.array( [ [1, 28], [2, 55], [3, 43], [4, 91], [5, 81], [6, 53], [7, 19], [8, 87], [9, 52], ] ), columns=["week", "price"]) with gr.Blocks() as demo: gr.LinePlot( value=simple, x="week", y="price", title="Stock Price Chart", container=True, width=400 ) demo.launch() pandas numpy

Description

Creates a line plot component to display data from a pandas DataFrame (as output). As this component does not accept user input, it is rarely used as an input component.

Behavior

As input component: (Rarely used) passes the data displayed in the line plot as an AltairPlotData dataclass, which includes the plot information as a JSON string, as well as the type of plot (in this case, "line").

Your function should accept one of these types:
def predict(
	value: AltairPlotData | None
)
	...

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:
def predict(ยทยทยท) -> pd.DataFrame | dict | None
	...	
	return value

Initialization

Parameters

Shortcuts

Class Interface String Shortcut Initialization

gradio.LinePlot

"lineplot"

Uses default values

Demos

import math import pandas as pd import gradio as gr import datetime import numpy as np def get_time(): return datetime.datetime.now() plot_end = 2 * math.pi def get_plot(period=1): global plot_end x = np.arange(plot_end - 2 * math.pi, plot_end, 0.02) y = np.sin(2 * math.pi * period * x) update = gr.LinePlot( value=pd.DataFrame({"x": x, "y": y}), x="x", y="y", title="Plot (updates every second)", width=600, height=350, ) plot_end += 2 * math.pi if plot_end > 1000: plot_end = 2 * math.pi return update with gr.Blocks() as demo: with gr.Row(): with gr.Column(): c_time2 = gr.Textbox(label="Current Time refreshed every second") gr.Textbox( "Change the value of the slider to automatically update the plot", label="", ) period = gr.Slider( label="Period of plot", value=1, minimum=0, maximum=10, step=1 ) plot = gr.LinePlot(show_label=False) with gr.Column(): name = gr.Textbox(label="Enter your name") greeting = gr.Textbox(label="Greeting") button = gr.Button(value="Greet") button.click(lambda s: f"Hello {s}", name, greeting) demo.load(lambda: datetime.datetime.now(), None, c_time2, every=1) dep = demo.load(get_plot, None, plot, every=1) period.change(get_plot, period, plot, every=1, cancels=[dep]) if __name__ == "__main__": demo.queue().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 LinePlot component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below.

Listener Description

LinePlot.select(fn, ยทยทยท)

Event listener for when the user selects or deselects the LinePlot. Uses event data gradio.SelectData to carry value referring to the label of the LinePlot, and selected to refer to state of the LinePlot. See EventData documentation on how to use this event data

Event Parameters

Parameters