Skip to main content
The Plot component displays plots from matplotlib, plotly, altair, or bokeh.

Basic usage

import gradio as gr
import matplotlib.pyplot as plt

def create_plot():
    fig, ax = plt.subplots()
    ax.plot([1, 2, 3, 4], [1, 4, 2, 3])
    return fig

gr.Interface(
    fn=create_plot,
    inputs=gr.Button("Generate"),
    outputs=gr.Plot()
).launch()

Constructor

value
Any | None
default:"None"
Default plot object (matplotlib, plotly, altair, or bokeh figure)
format
str
default:"'webp'"
File format for matplotlib plots (e.g., “png”, “jpg”)
label
str | None
default:"None"
Label displayed above component

Events

  • change - Triggered when plot changes

Examples

Matplotlib

import gradio as gr
import matplotlib.pyplot as plt
import numpy as np

def plot_sine():
    x = np.linspace(0, 2*np.pi, 100)
    y = np.sin(x)
    
    fig, ax = plt.subplots()
    ax.plot(x, y)
    ax.set_title("Sine Wave")
    return fig

gr.Interface(fn=plot_sine, inputs=None, outputs=gr.Plot()).launch()

Plotly

import gradio as gr
import plotly.graph_objects as go

def create_plotly():
    fig = go.Figure(
        data=[go.Bar(x=[1, 2, 3], y=[4, 5, 6])]
    )
    fig.update_layout(title="Bar Chart")
    return fig

gr.Interface(fn=create_plotly, inputs=None, outputs=gr.Plot()).launch()