Skip to content

Commit e35a521

Browse files
feat(seaborn): implement contour-density (#2572)
## Implementation: `contour-density` - seaborn Implements the **seaborn** version of `contour-density`. **File:** `plots/contour-density/implementations/seaborn.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20593350753)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 9789951 commit e35a521

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
""" pyplots.ai
2+
contour-density: Density Contour Plot
3+
Library: seaborn 0.13.2 | Python 3.13.11
4+
Quality: 93/100 | Created: 2025-12-30
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
import seaborn as sns
10+
11+
12+
# Data - bivariate normal distributions with two clusters
13+
np.random.seed(42)
14+
15+
# Main cluster
16+
n1 = 300
17+
x1 = np.random.normal(loc=5, scale=1.5, size=n1)
18+
y1 = np.random.normal(loc=5, scale=1.5, size=n1)
19+
20+
# Secondary cluster
21+
n2 = 150
22+
x2 = np.random.normal(loc=9, scale=1.0, size=n2)
23+
y2 = np.random.normal(loc=8, scale=1.0, size=n2)
24+
25+
# Combine clusters
26+
x = np.concatenate([x1, x2])
27+
y = np.concatenate([y1, y2])
28+
29+
# Create figure
30+
fig, ax = plt.subplots(figsize=(16, 9))
31+
32+
# Density contour plot using seaborn's kdeplot (filled)
33+
sns.kdeplot(x=x, y=y, ax=ax, levels=10, fill=True, cmap="viridis", alpha=0.8)
34+
35+
# Add contour lines for clarity
36+
sns.kdeplot(x=x, y=y, ax=ax, levels=10, color="#306998", linewidths=1.5, alpha=0.7)
37+
38+
# Scatter plot overlay for context (small, semi-transparent points)
39+
ax.scatter(x, y, s=15, color="white", alpha=0.3, edgecolors="none")
40+
41+
# Styling
42+
ax.set_xlabel("X Variable (units)", fontsize=20)
43+
ax.set_ylabel("Y Variable (units)", fontsize=20)
44+
ax.set_title("contour-density · seaborn · pyplots.ai", fontsize=24)
45+
ax.tick_params(axis="both", labelsize=16)
46+
ax.grid(True, alpha=0.3, linestyle="--")
47+
48+
plt.tight_layout()
49+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
library: seaborn
2+
specification_id: contour-density
3+
created: '2025-12-30T09:31:30Z'
4+
updated: '2025-12-30T09:41:02Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20593350753
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 0.13.2
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/contour-density/seaborn/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/contour-density/seaborn/plot_thumb.png
12+
preview_html: null
13+
quality_score: 93
14+
review:
15+
strengths:
16+
- Excellent use of seaborn kdeplot for 2D kernel density estimation with both filled
17+
and line contours
18+
- Two-cluster data effectively demonstrates density visualization capabilities
19+
- Viridis colormap provides excellent colorblind accessibility and visual appeal
20+
- Scatter overlay adds context without cluttering the visualization
21+
- Clean, well-structured code following KISS principles
22+
weaknesses:
23+
- No colorbar/legend to show the density scale mapping
24+
- Generic axis labels (X Variable, Y Variable) rather than a real-world scenario

0 commit comments

Comments
 (0)