Skip to content

Commit 0269256

Browse files
committed
Scratch work for creating graphs for presentations
1 parent 8633509 commit 0269256

9 files changed

+118
-0
lines changed

chart.png

2.99 MB
Loading

ipyleaflet.png

3.96 MB
Loading

ipyleaflet_pydeck.png

4.53 MB
Loading
4.31 MB
Loading
4.11 MB
Loading
4.57 MB
Loading

ipyleaflet_pydeck_speed.png

4.37 MB
Loading

tmp_graph.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import altair as alt
2+
from altair import datum
3+
4+
import pandas as pd
5+
6+
data = [
7+
["fiona", 232, "FlatGeobuf"],
8+
["pyogrio", 108, "FlatGeobuf"],
9+
["GeoArrow", 10, "FlatGeobuf"],
10+
["fiona", 227, "GeoPackage"],
11+
["pyogrio", 103, "GeoPackage"],
12+
["GeoArrow", 10, "GeoPackage"],
13+
]
14+
15+
# Create the pandas DataFrame
16+
df = pd.DataFrame(data, columns=["Method", "Read time (s)", "File Format"])
17+
18+
gp_chart = (
19+
alt.Chart(df)
20+
.mark_bar()
21+
.encode(
22+
alt.X("Read time (s)"),
23+
alt.Y("File Format", axis=alt.Axis(grid=True)),
24+
alt.Color("Method"),
25+
yOffset="Method",
26+
)
27+
)
28+
gp_chart = gp_chart.properties(
29+
title="Reading geospatial data to a GeoPandas GeoDataFrame",
30+
# width=alt.Step(80), # Adjust the width of bars if needed
31+
)
32+
33+
gp_chart
34+
gp_chart.save("chart.png", ppi=200, scale_factor=10)
35+
!pip install vl-convert-python
36+
37+
38+
39+
# Example data
40+
data = pd.DataFrame({"Category": ["A", "B", "C", "D"], "Value": [20, 35, 30, 25]})
41+
42+
# Create the Altair chart
43+
chart = alt.Chart(data).mark_bar().encode(x="Category", y="Value")
44+
45+
# Optionally, add titles and adjust appearance
46+
chart = chart.properties(
47+
title="Bar Chart Example",
48+
width=alt.Step(80), # Adjust the width of bars if needed
49+
)
50+
51+
# Show the chart
52+
chart

tmp_line_graph.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import altair as alt
2+
from vega_datasets import data
3+
4+
source = data.stocks()
5+
6+
source
7+
8+
alt.Chart(source).mark_line().encode(
9+
x="date:T",
10+
y="price:Q",
11+
color="symbol:N",
12+
)
13+
14+
import pandas as pd
15+
16+
data = [
17+
["ipyleaflet", 10_000, 1.16],
18+
["ipyleaflet", 50_000, 5.3],
19+
["ipyleaflet", 100_000, 12.4],
20+
["ipyleaflet", 150_000, 17.43],
21+
["ipyleaflet", 200_000, 24.84],
22+
["ipyleaflet", 300_000, 50.29],
23+
["pydeck", 10_000, 0.96],
24+
["pydeck", 50_000, 3.75],
25+
["pydeck", 100_000, 6.52],
26+
["pydeck", 250_000, 17.79],
27+
["pydeck", 500_000, 35.63],
28+
["pydeck", 750_000, 55.1],
29+
["pydeck", 1_000_000, 74.25],
30+
["lonboard", 100_000, 0.55],
31+
["lonboard", 500_000, 0.71],
32+
["lonboard", 1_000_000, 0.92],
33+
["lonboard", 2_000_000, 1.25],
34+
["lonboard", 3_000_000, 1.67],
35+
["lonboard", 5_000_000, 3.32],
36+
["lonboard", 7_500_000, 4.33],
37+
["lonboard", 10_000_000, 5.61],
38+
["lonboard", 15_000_000, 7.95],
39+
]
40+
41+
columns = ["Library", "# of rows", "Render time (s)"]
42+
df = pd.DataFrame(data, columns=columns)
43+
44+
color_scale = alt.Scale(
45+
domain=["ipyleaflet", "pydeck"], # , "lonboard"],
46+
range=["#4e79a7", "#f28e2b"], # , "#59A14F"],
47+
)
48+
49+
50+
chart = (
51+
alt.Chart(df)
52+
.mark_line()
53+
.encode(
54+
x=f"{columns[1]}:Q",
55+
y=f"{columns[2]}:Q",
56+
color=alt.Color(shorthand=f"{columns[0]}:N", scale=color_scale),
57+
)
58+
)
59+
chart = chart.properties(
60+
title="Time to render interactive map by number of points",
61+
# width=alt.Step(80), # Adjust the width of bars if needed
62+
)
63+
chart
64+
# chart.save("ipyleaflet.png", ppi=200, scale_factor=10)
65+
chart.save("ipyleaflet_pydeck.png", ppi=200, scale_factor=10)
66+
# !pip install vl-convert-python

0 commit comments

Comments
 (0)