mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-30 11:00:11 +08:00
da05e59a53
* changes
* add changeset
* changes
* changes
* Update many-tips-create.md
* notebooks
* chanegs
* changes
* changes
* changes
* changes
* changes
* changes
* changes
* changes
* changes
* changes
* changew
* changes
* changes
* changes
* changes
* chanegs
* changes
* changes
* changes
* changes
* changes
* changes
* changes
* changes
* changes
* changes
* changes
* changes
* changes
* Revert "changes"
This reverts commit 0868c25c56
.
* changes
* changes
* changes
* changes
* changes
* changes
* change
* changes
* chaneges
* changes
* chagnes
* changes
* changes
* changes
* changes
* changes
* fix typing
* changes
---------
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
import gradio as gr
|
|
from vega_datasets import data
|
|
|
|
cars = data.cars()
|
|
iris = data.iris()
|
|
|
|
# # Or generate your own fake data
|
|
|
|
# import pandas as pd
|
|
# import random
|
|
|
|
# cars_data = {
|
|
# "Name": ["car name " + f" {int(i/10)}" for i in range(400)],
|
|
# "Miles_per_Gallon": [random.randint(10, 30) for _ in range(400)],
|
|
# "Origin": [random.choice(["USA", "Europe", "Japan"]) for _ in range(400)],
|
|
# "Horsepower": [random.randint(50, 250) for _ in range(400)],
|
|
# }
|
|
|
|
# iris_data = {
|
|
# "petalWidth": [round(random.uniform(0, 2.5), 2) for _ in range(150)],
|
|
# "petalLength": [round(random.uniform(0, 7), 2) for _ in range(150)],
|
|
# "species": [
|
|
# random.choice(["setosa", "versicolor", "virginica"]) for _ in range(150)
|
|
# ],
|
|
# }
|
|
|
|
# cars = pd.DataFrame(cars_data)
|
|
# iris = pd.DataFrame(iris_data)
|
|
|
|
|
|
def scatter_plot_fn(dataset):
|
|
if dataset == "iris":
|
|
return gr.ScatterPlot(
|
|
value=iris,
|
|
x="petalWidth",
|
|
y="petalLength",
|
|
color="species",
|
|
title="Iris Dataset",
|
|
color_legend_title="Species",
|
|
x_title="Petal Width",
|
|
y_title="Petal Length",
|
|
tooltip=["petalWidth", "petalLength", "species"],
|
|
caption="",
|
|
)
|
|
else:
|
|
return gr.ScatterPlot(
|
|
value=cars,
|
|
x="Horsepower",
|
|
y="Miles_per_Gallon",
|
|
color="Origin",
|
|
tooltip="Name",
|
|
title="Car Data",
|
|
y_title="Miles per Gallon",
|
|
color_legend_title="Origin of Car",
|
|
caption="MPG vs Horsepower of various cars",
|
|
)
|
|
|
|
|
|
with gr.Blocks() as scatter_plot:
|
|
with gr.Row():
|
|
with gr.Column():
|
|
dataset = gr.Dropdown(choices=["cars", "iris"], value="cars")
|
|
with gr.Column():
|
|
plot = gr.ScatterPlot()
|
|
dataset.change(scatter_plot_fn, inputs=dataset, outputs=plot)
|
|
scatter_plot.load(fn=scatter_plot_fn, inputs=dataset, outputs=plot)
|
|
|
|
if __name__ == "__main__":
|
|
scatter_plot.launch()
|