Basic usage
Constructor
Default plot object (matplotlib, plotly, altair, or bokeh figure)
File format for matplotlib plots (e.g., “png”, “jpg”)
Label displayed above component
Events
- change - Triggered when plot changes
Display interactive plots from various plotting libraries
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()
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()
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()