Skip to content

Commit 7c1ffc0

Browse files
update(hexbin-basic): letsplot — comprehensive quality review
- Improved geom_hex usage - Better color scales and themes - Enhanced layout and legibility
1 parent 60de10e commit 7c1ffc0

2 files changed

Lines changed: 44 additions & 25 deletions

File tree

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" pyplots.ai
22
hexbin-basic: Basic Hexbin Plot
3-
Library: letsplot 4.8.1 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: letsplot 4.8.2 | Python 3.14.3
4+
Quality: /100 | Updated: 2026-02-21
55
"""
66

77
import numpy as np
@@ -16,6 +16,7 @@
1616
ggplot,
1717
ggsize,
1818
labs,
19+
layer_tooltips,
1920
scale_fill_viridis,
2021
theme,
2122
theme_minimal,
@@ -25,37 +26,55 @@
2526

2627
LetsPlot.setup_html()
2728

28-
# Data - Generate clustered bivariate distribution for density visualization
29+
# Data - Simulated GPS ping density across a metro area (km from city center)
2930
np.random.seed(42)
3031
n_points = 10000
3132

32-
# Create multiple clusters to demonstrate density patterns in hexbin visualization
33-
cluster1_x = np.random.randn(n_points // 2) * 1.5 + 3
34-
cluster1_y = np.random.randn(n_points // 2) * 1.5 + 3
35-
cluster2_x = np.random.randn(n_points // 3) * 1.2 - 2
36-
cluster2_y = np.random.randn(n_points // 3) * 1.2 + 1
37-
cluster3_x = np.random.randn(n_points // 6) * 0.6 + 0
38-
cluster3_y = np.random.randn(n_points // 6) * 0.6 - 3
33+
# Downtown core - dense commercial district
34+
downtown_east = np.random.randn(n_points // 2) * 1.5 + 4
35+
downtown_north = np.random.randn(n_points // 2) * 1.5 + 3
3936

40-
x = np.concatenate([cluster1_x, cluster2_x, cluster3_x])
41-
y = np.concatenate([cluster1_y, cluster2_y, cluster3_y])
37+
# University campus - moderate foot traffic
38+
campus_east = np.random.randn(n_points // 3) * 1.0 - 3
39+
campus_north = np.random.randn(n_points // 3) * 1.0 + 1
4240

43-
df = pd.DataFrame({"x": x, "y": y})
41+
# Transit hub - tight cluster of commuters
42+
transit_east = np.random.randn(n_points // 6) * 0.5 + 0.5
43+
transit_north = np.random.randn(n_points // 6) * 0.5 - 3.5
4444

45-
# Plot - Hexagonal binning to reveal density patterns
45+
east_km = np.concatenate([downtown_east, campus_east, transit_east])
46+
north_km = np.concatenate([downtown_north, campus_north, transit_north])
47+
48+
df = pd.DataFrame({"east_km": east_km, "north_km": north_km})
49+
50+
# Plot - Hexagonal binning to reveal pedestrian density hotspots
4651
plot = (
47-
ggplot(df, aes(x="x", y="y"))
48-
+ geom_hex(bins=[35, 35])
49-
+ scale_fill_viridis(name="Count", option="viridis")
50-
+ labs(x="X Coordinate", y="Y Coordinate", title="hexbin-basic · letsplot · pyplots.ai")
52+
ggplot(df, aes(x="east_km", y="north_km"))
53+
+ geom_hex(
54+
aes(fill="..count.."),
55+
bins=[30, 30],
56+
color="#FFFFFF",
57+
size=0.3,
58+
tooltips=layer_tooltips()
59+
.title("Hex Bin")
60+
.line("pings|@..count..")
61+
.line("density|@..density..")
62+
.format("@..density..", ".3f"),
63+
)
64+
+ scale_fill_viridis(name="Ping Count", option="viridis")
65+
+ labs(
66+
x="East-West (km from center)",
67+
y="North-South (km from center)",
68+
title="hexbin-basic \u00b7 letsplot \u00b7 pyplots.ai",
69+
)
5170
+ theme_minimal()
5271
+ theme(
5372
axis_title=element_text(size=22),
5473
axis_text=element_text(size=18),
5574
plot_title=element_text(size=26),
5675
legend_text=element_text(size=16),
5776
legend_title=element_text(size=18),
58-
panel_grid=element_line(color="#CCCCCC", size=0.4, linetype="dashed"),
77+
panel_grid=element_line(color="#E0E0E0", size=0.3, linetype="dashed"),
5978
panel_background=element_rect(fill="#FAFAFA"),
6079
)
6180
+ ggsize(1600, 900)
@@ -64,5 +83,5 @@
6483
# Save PNG (scale=3 gives 4800x2700)
6584
ggsave(plot, "plot.png", path=".", scale=3)
6685

67-
# Save HTML for interactivity
86+
# Save HTML for interactive tooltips
6887
ggsave(plot, "plot.html", path=".")

plots/hexbin-basic/metadata/letsplot.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
library: letsplot
22
specification_id: hexbin-basic
33
created: '2025-12-23T01:31:08Z'
4-
updated: '2025-12-23T06:54:49Z'
5-
generated_by: claude-opus-4-5-20251101
4+
updated: '2026-02-21T21:02:15+00:00'
5+
generated_by: claude-opus-4-6
66
workflow_run: 20448655355
77
issue: 0
8-
python_version: 3.13.11
9-
library_version: 4.8.1
8+
python_version: 3.14.3
9+
library_version: 4.8.2
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/hexbin-basic/letsplot/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/hexbin-basic/letsplot/plot_thumb.png
1212
preview_html: https://storage.googleapis.com/pyplots-images/plots/hexbin-basic/letsplot/plot.html
13-
quality_score: 91
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques:

0 commit comments

Comments
 (0)