Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions plots/contour-density/implementations/seaborn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
""" pyplots.ai
contour-density: Density Contour Plot
Library: seaborn 0.13.2 | Python 3.13.11
Quality: 93/100 | Created: 2025-12-30
"""

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns


# Data - bivariate normal distributions with two clusters
np.random.seed(42)

# Main cluster
n1 = 300
x1 = np.random.normal(loc=5, scale=1.5, size=n1)
y1 = np.random.normal(loc=5, scale=1.5, size=n1)

# Secondary cluster
n2 = 150
x2 = np.random.normal(loc=9, scale=1.0, size=n2)
y2 = np.random.normal(loc=8, scale=1.0, size=n2)

# Combine clusters
x = np.concatenate([x1, x2])
y = np.concatenate([y1, y2])

# Create figure
fig, ax = plt.subplots(figsize=(16, 9))

# Density contour plot using seaborn's kdeplot (filled)
sns.kdeplot(x=x, y=y, ax=ax, levels=10, fill=True, cmap="viridis", alpha=0.8)

# Add contour lines for clarity
sns.kdeplot(x=x, y=y, ax=ax, levels=10, color="#306998", linewidths=1.5, alpha=0.7)

# Scatter plot overlay for context (small, semi-transparent points)
ax.scatter(x, y, s=15, color="white", alpha=0.3, edgecolors="none")

# Styling
ax.set_xlabel("X Variable (units)", fontsize=20)
ax.set_ylabel("Y Variable (units)", fontsize=20)
ax.set_title("contour-density · seaborn · pyplots.ai", fontsize=24)
ax.tick_params(axis="both", labelsize=16)
ax.grid(True, alpha=0.3, linestyle="--")

plt.tight_layout()
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
24 changes: 24 additions & 0 deletions plots/contour-density/metadata/seaborn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
library: seaborn
specification_id: contour-density
created: '2025-12-30T09:31:30Z'
updated: '2025-12-30T09:41:02Z'
generated_by: claude-opus-4-5-20251101
workflow_run: 20593350753
issue: 0
python_version: 3.13.11
library_version: 0.13.2
preview_url: https://storage.googleapis.com/pyplots-images/plots/contour-density/seaborn/plot.png
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/contour-density/seaborn/plot_thumb.png
preview_html: null
quality_score: 93
review:
strengths:
- Excellent use of seaborn kdeplot for 2D kernel density estimation with both filled
and line contours
- Two-cluster data effectively demonstrates density visualization capabilities
- Viridis colormap provides excellent colorblind accessibility and visual appeal
- Scatter overlay adds context without cluttering the visualization
- Clean, well-structured code following KISS principles
weaknesses:
- No colorbar/legend to show the density scale mapping
- Generic axis labels (X Variable, Y Variable) rather than a real-world scenario