Skip to content

Commit 2b765bd

Browse files
feat(seaborn): implement bar-categorical (#2649)
## Implementation: `bar-categorical` - seaborn Implements the **seaborn** version of `bar-categorical`. **File:** `plots/bar-categorical/implementations/seaborn.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20595333274)* --------- 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 199ca6b commit 2b765bd

2 files changed

Lines changed: 75 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+
bar-categorical: Categorical Count Bar Chart
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 - Survey responses about preferred programming languages
13+
np.random.seed(42)
14+
languages = ["Python", "JavaScript", "Java", "C++", "Go", "Rust", "TypeScript"]
15+
# Weighted probabilities to create realistic distribution (Python most popular)
16+
weights = [0.28, 0.22, 0.15, 0.12, 0.10, 0.07, 0.06]
17+
responses = np.random.choice(languages, size=500, p=weights)
18+
19+
# Create plot
20+
fig, ax = plt.subplots(figsize=(16, 9))
21+
22+
# Use seaborn countplot for automatic frequency counting
23+
sns.countplot(
24+
x=responses,
25+
order=["Python", "JavaScript", "Java", "C++", "Go", "Rust", "TypeScript"],
26+
hue=responses,
27+
hue_order=["Python", "JavaScript", "Java", "C++", "Go", "Rust", "TypeScript"],
28+
palette=["#306998", "#FFD43B", "#5382A1", "#00599C", "#00ADD8", "#DEA584", "#3178C6"],
29+
legend=False,
30+
ax=ax,
31+
)
32+
33+
# Add count labels on top of bars
34+
for container in ax.containers:
35+
ax.bar_label(container, fontsize=16, padding=5)
36+
37+
# Styling
38+
ax.set_xlabel("Programming Language", fontsize=20)
39+
ax.set_ylabel("Number of Responses", fontsize=20)
40+
ax.set_title("bar-categorical · seaborn · pyplots.ai", fontsize=24)
41+
ax.tick_params(axis="both", labelsize=16)
42+
ax.grid(axis="y", alpha=0.3, linestyle="--")
43+
44+
# Remove top and right spines for cleaner look
45+
ax.spines["top"].set_visible(False)
46+
ax.spines["right"].set_visible(False)
47+
48+
plt.tight_layout()
49+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
library: seaborn
2+
specification_id: bar-categorical
3+
created: '2025-12-30T11:21:28Z'
4+
updated: '2025-12-30T11:24:36Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20595333274
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/bar-categorical/seaborn/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bar-categorical/seaborn/plot_thumb.png
12+
preview_html: null
13+
quality_score: 93
14+
review:
15+
strengths:
16+
- Excellent use of sns.countplot for automatic frequency counting - the core seaborn
17+
feature for this plot type
18+
- Clean, professional appearance with removed top/right spines
19+
- Well-chosen custom color palette with distinct colors for each programming language
20+
- Count labels on bars enhance readability
21+
- Properly handles seaborn 0.14+ API by using hue parameter with palette
22+
weaknesses:
23+
- Could use seaborn built-in themes (sns.set_theme or sns.set_style) for more distinctive
24+
seaborn styling
25+
- The order parameter manually specifies the order rather than computing it from
26+
the data

0 commit comments

Comments
 (0)