Skip to content

Commit 9dc514c

Browse files
update(hexbin-basic): seaborn — comprehensive quality review
- Simplified code, improved hexbin styling - Better color palette and density visualization - Enhanced layout and legibility
1 parent 60de10e commit 9dc514c

2 files changed

Lines changed: 23 additions & 28 deletions

File tree

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,58 @@
11
""" pyplots.ai
22
hexbin-basic: Basic Hexbin Plot
3-
Library: seaborn 0.13.2 | Python 3.13.11
4-
Quality: 90/100 | Created: 2025-12-23
3+
Library: seaborn 0.13.2 | Python 3.14.3
4+
Quality: /100 | Updated: 2026-02-21
55
"""
66

77
import numpy as np
8-
import pandas as pd
98
import seaborn as sns
9+
from matplotlib.colors import LogNorm
1010

1111

1212
# Data - simulate GPS coordinates for urban traffic hotspot analysis
1313
np.random.seed(42)
1414

15-
# Create realistic GPS coordinate clusters representing traffic hotspots
16-
# Using a larger dataset (50,000 points) to demonstrate hexbin advantage over scatter
15+
# 50,000 points to demonstrate hexbin advantage over scatter
1716
n_points = 50000
1817

19-
# Downtown business district - high density
18+
# Downtown business district - high density cluster
2019
downtown = np.random.multivariate_normal([-73.985, 40.748], [[0.0001, 0.00005], [0.00005, 0.0001]], n_points // 2)
2120

22-
# Airport area - medium density
21+
# Airport area - medium density cluster
2322
airport = np.random.multivariate_normal([-73.875, 40.775], [[0.00008, -0.00003], [-0.00003, 0.00008]], n_points // 3)
2423

2524
# Shopping district - smaller cluster
2625
shopping = np.random.multivariate_normal([-73.965, 40.785], [[0.00004, 0], [0, 0.00006]], n_points // 6)
2726

28-
# Combine clusters into DataFrame for seaborn
2927
longitude = np.concatenate([downtown[:, 0], airport[:, 0], shopping[:, 0]])
3028
latitude = np.concatenate([downtown[:, 1], airport[:, 1], shopping[:, 1]])
31-
df = pd.DataFrame({"Longitude": longitude, "Latitude": latitude})
3229

33-
# Set seaborn style for clean aesthetics
30+
# Plot - seaborn JointGrid with hexbin and marginal distributions
3431
sns.set_theme(style="whitegrid", context="talk", font_scale=1.2)
3532

36-
# Create JointGrid for hexbin with marginal distributions
37-
g = sns.JointGrid(data=df, x="Longitude", y="Latitude", height=12, ratio=5, space=0.2)
33+
g = sns.JointGrid(x=longitude, y=latitude, height=12, ratio=5, space=0.15)
3834

39-
# Main hexbin plot using plot_joint
40-
hb = g.ax_joint.hexbin(df["Longitude"], df["Latitude"], gridsize=35, cmap="viridis", mincnt=1, edgecolors="none")
35+
# Main hexbin with log-normalized color scale for wide density variation
36+
hb = g.ax_joint.hexbin(longitude, latitude, gridsize=35, cmap="viridis", mincnt=1, norm=LogNorm(), edgecolors="none")
4137

42-
# Marginal distributions using seaborn's histplot
43-
g.plot_marginals(sns.histplot, kde=True, color="#306998", alpha=0.6, linewidth=0)
38+
# Marginal distributions - distinctive seaborn feature
39+
g.plot_marginals(sns.kdeplot, color="#306998", fill=True, alpha=0.4, linewidth=2)
4440

45-
# Add colorbar to show density scale
41+
# Colorbar for density scale
4642
cbar = g.figure.colorbar(hb, ax=g.ax_joint, pad=0.02, shrink=0.8)
47-
cbar.set_label("Point Count", fontsize=20)
43+
cbar.set_label("Point Count (log scale)", fontsize=20)
4844
cbar.ax.tick_params(labelsize=16)
4945

50-
# Labels and title with proper sizing
46+
# Style
5147
g.ax_joint.set_xlabel("Longitude (°W)", fontsize=20)
5248
g.ax_joint.set_ylabel("Latitude (°N)", fontsize=20)
5349
g.ax_joint.tick_params(axis="both", labelsize=16)
50+
g.ax_joint.grid(True, alpha=0.2, linestyle="--", linewidth=0.8)
51+
g.ax_joint.spines["top"].set_visible(False)
52+
g.ax_joint.spines["right"].set_visible(False)
5453

55-
# Subtle grid on main plot
56-
g.ax_joint.grid(True, alpha=0.3, linestyle="--", linewidth=0.8)
57-
58-
# Title at top of figure
5954
g.figure.suptitle("hexbin-basic · seaborn · pyplots.ai", fontsize=24, y=0.98)
6055

61-
# Adjust layout to prevent clipping
56+
# Save
6257
g.figure.tight_layout(rect=[0, 0, 1, 0.96])
6358
g.savefig("plot.png", dpi=300, bbox_inches="tight")

plots/hexbin-basic/metadata/seaborn.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
library: seaborn
22
specification_id: hexbin-basic
33
created: '2025-12-23T01:30:30Z'
4-
updated: '2025-12-23T07:01:09Z'
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: 20448651717
77
issue: 0
8-
python_version: 3.13.11
8+
python_version: 3.14.3
99
library_version: 0.13.2
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/hexbin-basic/seaborn/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/hexbin-basic/seaborn/plot_thumb.png
1212
preview_html: null
13-
quality_score: 90
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques:

0 commit comments

Comments
 (0)