Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- bar_plot_demo.py +66 -100
- data.py +20 -0
- line_plot_demo.py +59 -72
- requirements.txt +2 -2
- run.ipynb +1 -1
- run.py +7 -7
- scatter_plot_demo.py +64 -39
bar_plot_demo.py
CHANGED
@@ -1,111 +1,77 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
color="site",
|
33 |
-
group=None,
|
34 |
-
title="Barley Yield Data",
|
35 |
-
tooltip=['variety', 'site'],
|
36 |
-
y_lim=None,
|
37 |
-
x_title=None,
|
38 |
-
y_title=None,
|
39 |
-
vertical=True,
|
40 |
-
)
|
41 |
-
elif display == "grouped":
|
42 |
-
return gr.BarPlot(
|
43 |
-
barley.astype({"year": str}),
|
44 |
-
x="year",
|
45 |
-
y="yield",
|
46 |
-
color="year",
|
47 |
-
group="site",
|
48 |
-
title="Barley Yield by Year and Site",
|
49 |
-
tooltip=["yield", "site", "year"],
|
50 |
-
y_lim=None,
|
51 |
-
x_title=None,
|
52 |
-
y_title=None,
|
53 |
-
vertical=True,
|
54 |
)
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
group=None,
|
62 |
-
title="Simple Bar Plot with made up data",
|
63 |
-
tooltip=['a', 'b'],
|
64 |
-
y_lim=[20, 100],
|
65 |
-
x_title="Variable A",
|
66 |
-
y_title="Variable B",
|
67 |
-
vertical=False,
|
68 |
)
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
y_title=None,
|
81 |
-
vertical=False,
|
82 |
)
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
title="Barley Yield by Year and Site",
|
91 |
-
group_title="",
|
92 |
-
tooltip=["yield", "site", "year"],
|
93 |
-
y_lim=None,
|
94 |
-
x_title=None,
|
95 |
-
y_title=None,
|
96 |
-
vertical=False
|
97 |
)
|
98 |
|
99 |
|
100 |
-
with gr.Blocks() as bar_plot:
|
101 |
-
display = gr.Dropdown(
|
102 |
-
choices=["simple", "stacked", "grouped", "simple-horizontal", "stacked-horizontal", "grouped-horizontal"],
|
103 |
-
value="simple",
|
104 |
-
label="Type of Bar Plot"
|
105 |
-
)
|
106 |
-
plot = gr.BarPlot(show_label=False)
|
107 |
-
display.change(bar_plot_fn, inputs=display, outputs=plot)
|
108 |
-
bar_plot.load(fn=bar_plot_fn, inputs=display, outputs=plot)
|
109 |
-
|
110 |
if __name__ == "__main__":
|
111 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from data import temp_sensor_data, food_rating_data
|
4 |
|
5 |
+
with gr.Blocks() as bar_plots:
|
6 |
+
with gr.Row():
|
7 |
+
start = gr.DateTime("2021-01-01 00:00:00", label="Start")
|
8 |
+
end = gr.DateTime("2021-01-05 00:00:00", label="End")
|
9 |
+
apply_btn = gr.Button("Apply", scale=0)
|
10 |
+
with gr.Row():
|
11 |
+
group_by = gr.Radio(["None", "30m", "1h", "4h", "1d"], value="None", label="Group by")
|
12 |
+
aggregate = gr.Radio(["sum", "mean", "median", "min", "max"], value="sum", label="Aggregation")
|
13 |
|
14 |
+
temp_by_time = gr.BarPlot(
|
15 |
+
temp_sensor_data,
|
16 |
+
x="time",
|
17 |
+
y="temperature",
|
18 |
+
)
|
19 |
+
temp_by_time_location = gr.BarPlot(
|
20 |
+
temp_sensor_data,
|
21 |
+
x="time",
|
22 |
+
y="temperature",
|
23 |
+
color="location",
|
24 |
+
)
|
25 |
|
26 |
+
time_graphs = [temp_by_time, temp_by_time_location]
|
27 |
+
group_by.change(
|
28 |
+
lambda group: [gr.BarPlot(x_bin=None if group == "None" else group)] * len(time_graphs),
|
29 |
+
group_by,
|
30 |
+
time_graphs
|
31 |
+
)
|
32 |
+
aggregate.change(
|
33 |
+
lambda aggregate: [gr.BarPlot(y_aggregate=aggregate)] * len(time_graphs),
|
34 |
+
aggregate,
|
35 |
+
time_graphs
|
36 |
+
)
|
37 |
+
|
38 |
+
|
39 |
+
def rescale(select: gr.SelectData):
|
40 |
+
return select.index
|
41 |
+
rescale_evt = gr.on([plot.select for plot in time_graphs], rescale, None, [start, end])
|
42 |
+
|
43 |
+
for trigger in [apply_btn.click, rescale_evt.then]:
|
44 |
+
trigger(
|
45 |
+
lambda start, end: [gr.BarPlot(x_lim=[start, end])] * len(time_graphs), [start, end], time_graphs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
)
|
47 |
+
|
48 |
+
with gr.Row():
|
49 |
+
price_by_cuisine = gr.BarPlot(
|
50 |
+
food_rating_data,
|
51 |
+
x="cuisine",
|
52 |
+
y="price",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
)
|
54 |
+
with gr.Column(scale=0):
|
55 |
+
gr.Button("Sort $ > $$$").click(lambda: gr.BarPlot(sort="y"), None, price_by_cuisine)
|
56 |
+
gr.Button("Sort $$$ > $").click(lambda: gr.BarPlot(sort="-y"), None, price_by_cuisine)
|
57 |
+
gr.Button("Sort A > Z").click(lambda: gr.BarPlot(sort=["Chinese", "Italian", "Mexican"]), None, price_by_cuisine)
|
58 |
+
|
59 |
+
with gr.Row():
|
60 |
+
price_by_rating = gr.BarPlot(
|
61 |
+
food_rating_data,
|
62 |
+
x="rating",
|
63 |
+
y="price",
|
64 |
+
x_bin=1,
|
|
|
|
|
65 |
)
|
66 |
+
price_by_rating_color = gr.BarPlot(
|
67 |
+
food_rating_data,
|
68 |
+
x="rating",
|
69 |
+
y="price",
|
70 |
+
color="cuisine",
|
71 |
+
x_bin=1,
|
72 |
+
color_map={"Italian": "red", "Mexican": "green", "Chinese": "blue"},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
)
|
74 |
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
if __name__ == "__main__":
|
77 |
+
bar_plots.launch()
|
data.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from random import randint, choice, random
|
3 |
+
|
4 |
+
temp_sensor_data = pd.DataFrame(
|
5 |
+
{
|
6 |
+
"time": pd.date_range("2021-01-01", end="2021-01-05", periods=200),
|
7 |
+
"temperature": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)],
|
8 |
+
"humidity": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)],
|
9 |
+
"location": ["indoor", "outdoor"] * 100,
|
10 |
+
}
|
11 |
+
)
|
12 |
+
|
13 |
+
food_rating_data = pd.DataFrame(
|
14 |
+
{
|
15 |
+
"cuisine": [["Italian", "Mexican", "Chinese"][i % 3] for i in range(100)],
|
16 |
+
"rating": [random() * 4 + 0.5 * (i % 3) for i in range(100)],
|
17 |
+
"price": [randint(10, 50) + 4 * (i % 3) for i in range(100)],
|
18 |
+
"wait": [random() for i in range(100)],
|
19 |
+
}
|
20 |
+
)
|
line_plot_demo.py
CHANGED
@@ -1,82 +1,69 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
def line_plot_fn(dataset):
|
14 |
-
if dataset == "stocks":
|
15 |
-
return gr.LinePlot(
|
16 |
-
stocks,
|
17 |
-
x="date",
|
18 |
-
y="price",
|
19 |
-
color="symbol",
|
20 |
-
x_lim=None,
|
21 |
-
y_lim=None,
|
22 |
-
stroke_dash=None,
|
23 |
-
tooltip=['date', 'price', 'symbol'],
|
24 |
-
overlay_point=False,
|
25 |
-
title="Stock Prices",
|
26 |
-
stroke_dash_legend_title=None,
|
27 |
-
)
|
28 |
-
elif dataset == "climate":
|
29 |
-
return gr.LinePlot(
|
30 |
-
climate,
|
31 |
-
x="DATE",
|
32 |
-
y="HLY-TEMP-NORMAL",
|
33 |
-
color=None,
|
34 |
-
x_lim=None,
|
35 |
-
y_lim=[250, 500],
|
36 |
-
stroke_dash=None,
|
37 |
-
tooltip=['DATE', 'HLY-TEMP-NORMAL'],
|
38 |
-
overlay_point=False,
|
39 |
-
title="Climate",
|
40 |
-
stroke_dash_legend_title=None,
|
41 |
-
)
|
42 |
-
elif dataset == "seattle_weather":
|
43 |
-
return gr.LinePlot(
|
44 |
-
seattle_weather,
|
45 |
-
x="date",
|
46 |
-
y="temp_min",
|
47 |
-
color=None,
|
48 |
-
x_lim=None,
|
49 |
-
y_lim=None,
|
50 |
-
stroke_dash=None,
|
51 |
-
tooltip=["weather", "date"],
|
52 |
-
overlay_point=True,
|
53 |
-
title="Seattle Weather",
|
54 |
-
stroke_dash_legend_title=None,
|
55 |
-
)
|
56 |
-
elif dataset == "gapminder":
|
57 |
-
return gr.LinePlot(
|
58 |
-
gapminder,
|
59 |
-
x="year",
|
60 |
-
y="life_expect",
|
61 |
-
color="country",
|
62 |
-
x_lim=[1950, 2010],
|
63 |
-
y_lim=None,
|
64 |
-
stroke_dash="cluster",
|
65 |
-
tooltip=['country', 'life_expect'],
|
66 |
-
overlay_point=False,
|
67 |
-
title="Life expectancy for countries",
|
68 |
-
)
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
)
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
|
81 |
if __name__ == "__main__":
|
82 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from data import temp_sensor_data, food_rating_data
|
4 |
|
5 |
+
with gr.Blocks() as line_plots:
|
6 |
+
with gr.Row():
|
7 |
+
start = gr.DateTime("2021-01-01 00:00:00", label="Start")
|
8 |
+
end = gr.DateTime("2021-01-05 00:00:00", label="End")
|
9 |
+
apply_btn = gr.Button("Apply", scale=0)
|
10 |
+
with gr.Row():
|
11 |
+
group_by = gr.Radio(["None", "30m", "1h", "4h", "1d"], value="None", label="Group by")
|
12 |
+
aggregate = gr.Radio(["sum", "mean", "median", "min", "max"], value="sum", label="Aggregation")
|
13 |
|
14 |
+
temp_by_time = gr.LinePlot(
|
15 |
+
temp_sensor_data,
|
16 |
+
x="time",
|
17 |
+
y="temperature",
|
18 |
+
)
|
19 |
+
temp_by_time_location = gr.LinePlot(
|
20 |
+
temp_sensor_data,
|
21 |
+
x="time",
|
22 |
+
y="temperature",
|
23 |
+
color="location",
|
24 |
+
)
|
25 |
+
|
26 |
+
time_graphs = [temp_by_time, temp_by_time_location]
|
27 |
+
group_by.change(
|
28 |
+
lambda group: [gr.LinePlot(x_bin=None if group == "None" else group)] * len(time_graphs),
|
29 |
+
group_by,
|
30 |
+
time_graphs
|
31 |
+
)
|
32 |
+
aggregate.change(
|
33 |
+
lambda aggregate: [gr.LinePlot(y_aggregate=aggregate)] * len(time_graphs),
|
34 |
+
aggregate,
|
35 |
+
time_graphs
|
36 |
+
)
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
def rescale(select: gr.SelectData):
|
40 |
+
return select.index
|
41 |
+
rescale_evt = gr.on([plot.select for plot in time_graphs], rescale, None, [start, end])
|
42 |
+
|
43 |
+
for trigger in [apply_btn.click, rescale_evt.then]:
|
44 |
+
trigger(
|
45 |
+
lambda start, end: [gr.LinePlot(x_lim=[start, end])] * len(time_graphs), [start, end], time_graphs
|
46 |
+
)
|
47 |
|
48 |
+
price_by_cuisine = gr.LinePlot(
|
49 |
+
food_rating_data,
|
50 |
+
x="cuisine",
|
51 |
+
y="price",
|
52 |
)
|
53 |
+
with gr.Row():
|
54 |
+
price_by_rating = gr.LinePlot(
|
55 |
+
food_rating_data,
|
56 |
+
x="rating",
|
57 |
+
y="price",
|
58 |
+
)
|
59 |
+
price_by_rating_color = gr.LinePlot(
|
60 |
+
food_rating_data,
|
61 |
+
x="rating",
|
62 |
+
y="price",
|
63 |
+
color="cuisine",
|
64 |
+
color_map={"Italian": "red", "Mexican": "green", "Chinese": "blue"},
|
65 |
+
)
|
66 |
|
67 |
|
68 |
if __name__ == "__main__":
|
69 |
+
line_plots.launch()
|
requirements.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
gradio-client @ git+https://github.com/gradio-app/gradio@
|
2 |
-
https://gradio-builds.s3.amazonaws.com/
|
3 |
vega_datasets
|
|
|
1 |
+
gradio-client @ git+https://github.com/gradio-app/gradio@76c175935019833baef709a5cf401d2263ca72ee#subdirectory=client/python
|
2 |
+
https://gradio-builds.s3.amazonaws.com/76c175935019833baef709a5cf401d2263ca72ee/gradio-4.38.1-py3-none-any.whl
|
3 |
vega_datasets
|
run.ipynb
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: native_plots"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio vega_datasets"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/bar_plot_demo.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/line_plot_demo.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/scatter_plot_demo.py"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "from scatter_plot_demo import
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: native_plots"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio vega_datasets"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/bar_plot_demo.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/data.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/line_plot_demo.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/scatter_plot_demo.py"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "from scatter_plot_demo import scatter_plots\n", "from line_plot_demo import line_plots\n", "from bar_plot_demo import bar_plots\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Tabs():\n", " with gr.TabItem(\"Line Plot\"):\n", " line_plots.render()\n", " with gr.TabItem(\"Scatter Plot\"):\n", " scatter_plots.render()\n", " with gr.TabItem(\"Bar Plot\"):\n", " bar_plots.render()\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
from scatter_plot_demo import
|
4 |
-
from line_plot_demo import
|
5 |
-
from bar_plot_demo import
|
6 |
|
7 |
|
8 |
with gr.Blocks() as demo:
|
9 |
with gr.Tabs():
|
10 |
-
with gr.TabItem("Scatter Plot"):
|
11 |
-
scatter_plot.render()
|
12 |
with gr.TabItem("Line Plot"):
|
13 |
-
|
|
|
|
|
14 |
with gr.TabItem("Bar Plot"):
|
15 |
-
|
16 |
|
17 |
if __name__ == "__main__":
|
18 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
from scatter_plot_demo import scatter_plots
|
4 |
+
from line_plot_demo import line_plots
|
5 |
+
from bar_plot_demo import bar_plots
|
6 |
|
7 |
|
8 |
with gr.Blocks() as demo:
|
9 |
with gr.Tabs():
|
|
|
|
|
10 |
with gr.TabItem("Line Plot"):
|
11 |
+
line_plots.render()
|
12 |
+
with gr.TabItem("Scatter Plot"):
|
13 |
+
scatter_plots.render()
|
14 |
with gr.TabItem("Bar Plot"):
|
15 |
+
bar_plots.render()
|
16 |
|
17 |
if __name__ == "__main__":
|
18 |
demo.launch()
|
scatter_plot_demo.py
CHANGED
@@ -1,46 +1,71 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
)
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
tooltip="Name",
|
31 |
-
title="Car Data",
|
32 |
-
y_title="Miles per Gallon",
|
33 |
-
caption="MPG vs Horsepower of various cars",
|
34 |
-
height=None,
|
35 |
-
width=None,
|
36 |
)
|
37 |
|
38 |
|
39 |
-
with gr.Blocks() as scatter_plot:
|
40 |
-
dataset = gr.Dropdown(choices=["cars", "iris"], value="cars")
|
41 |
-
plot = gr.ScatterPlot(show_label=False)
|
42 |
-
dataset.change(scatter_plot_fn, inputs=dataset, outputs=plot)
|
43 |
-
scatter_plot.load(fn=scatter_plot_fn, inputs=dataset, outputs=plot)
|
44 |
-
|
45 |
if __name__ == "__main__":
|
46 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from data import temp_sensor_data, food_rating_data
|
4 |
|
5 |
+
with gr.Blocks() as scatter_plots:
|
6 |
+
with gr.Row():
|
7 |
+
start = gr.DateTime("2021-01-01 00:00:00", label="Start")
|
8 |
+
end = gr.DateTime("2021-01-05 00:00:00", label="End")
|
9 |
+
apply_btn = gr.Button("Apply", scale=0)
|
10 |
+
with gr.Row():
|
11 |
+
group_by = gr.Radio(["None", "30m", "1h", "4h", "1d"], value="None", label="Group by")
|
12 |
+
aggregate = gr.Radio(["sum", "mean", "median", "min", "max"], value="sum", label="Aggregation")
|
13 |
+
|
14 |
+
temp_by_time = gr.ScatterPlot(
|
15 |
+
temp_sensor_data,
|
16 |
+
x="time",
|
17 |
+
y="temperature",
|
18 |
+
)
|
19 |
+
temp_by_time_location = gr.ScatterPlot(
|
20 |
+
temp_sensor_data,
|
21 |
+
x="time",
|
22 |
+
y="temperature",
|
23 |
+
color="location",
|
24 |
+
)
|
25 |
+
|
26 |
+
time_graphs = [temp_by_time, temp_by_time_location]
|
27 |
+
group_by.change(
|
28 |
+
lambda group: [gr.ScatterPlot(x_bin=None if group == "None" else group)] * len(time_graphs),
|
29 |
+
group_by,
|
30 |
+
time_graphs
|
31 |
+
)
|
32 |
+
aggregate.change(
|
33 |
+
lambda aggregate: [gr.ScatterPlot(y_aggregate=aggregate)] * len(time_graphs),
|
34 |
+
aggregate,
|
35 |
+
time_graphs
|
36 |
+
)
|
37 |
+
|
38 |
+
|
39 |
+
# def rescale(select: gr.SelectData):
|
40 |
+
# return select.index
|
41 |
+
# rescale_evt = gr.on([plot.select for plot in time_graphs], rescale, None, [start, end])
|
42 |
+
|
43 |
+
# for trigger in [apply_btn.click, rescale_evt.then]:
|
44 |
+
# trigger(
|
45 |
+
# lambda start, end: [gr.ScatterPlot(x_lim=[start, end])] * len(time_graphs), [start, end], time_graphs
|
46 |
+
# )
|
47 |
+
|
48 |
+
price_by_cuisine = gr.ScatterPlot(
|
49 |
+
food_rating_data,
|
50 |
+
x="cuisine",
|
51 |
+
y="price",
|
52 |
+
)
|
53 |
+
with gr.Row():
|
54 |
+
price_by_rating = gr.ScatterPlot(
|
55 |
+
food_rating_data,
|
56 |
+
x="rating",
|
57 |
+
y="price",
|
58 |
+
color="wait",
|
59 |
+
show_actions_button=True,
|
60 |
)
|
61 |
+
price_by_rating_color = gr.ScatterPlot(
|
62 |
+
food_rating_data,
|
63 |
+
x="rating",
|
64 |
+
y="price",
|
65 |
+
color="cuisine",
|
66 |
+
# color_map={"Italian": "red", "Mexican": "green", "Chinese": "blue"},
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
)
|
68 |
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
if __name__ == "__main__":
|
71 |
+
scatter_plots.launch()
|