Skip to content

Commit 028f48c

Browse files
feat(matplotlib): implement bar-categorical (#2664)
## Implementation: `bar-categorical` - matplotlib Implements the **matplotlib** version of `bar-categorical`. **File:** `plots/bar-categorical/implementations/matplotlib.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20595333486)* --------- 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 601fec5 commit 028f48c

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
""" pyplots.ai
2+
bar-categorical: Categorical Count Bar Chart
3+
Library: matplotlib 3.10.8 | Python 3.13.11
4+
Quality: 94/100 | Created: 2025-12-30
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
import pandas as pd
10+
11+
12+
# Data - survey responses for product preference
13+
np.random.seed(42)
14+
categories = ["Product A", "Product B", "Product C", "Product D", "Product E"]
15+
probabilities = [0.30, 0.25, 0.20, 0.15, 0.10] # Different frequencies for variety
16+
raw_data = np.random.choice(categories, size=500, p=probabilities)
17+
18+
# Count frequencies
19+
df = pd.DataFrame({"Category": raw_data})
20+
counts = df["Category"].value_counts().sort_values(ascending=False)
21+
22+
# Create plot (4800x2700 px at 300 dpi = 16x9 inches)
23+
fig, ax = plt.subplots(figsize=(16, 9))
24+
25+
# Bar chart with Python Blue
26+
bars = ax.bar(counts.index, counts.values, color="#306998", edgecolor="#1e4a6e", linewidth=2)
27+
28+
# Add value labels on top of bars
29+
for bar, value in zip(bars, counts.values, strict=True):
30+
ax.text(
31+
bar.get_x() + bar.get_width() / 2,
32+
bar.get_height() + 5,
33+
str(value),
34+
ha="center",
35+
va="bottom",
36+
fontsize=18,
37+
fontweight="bold",
38+
)
39+
40+
# Styling
41+
ax.set_xlabel("Product Category", fontsize=20)
42+
ax.set_ylabel("Count (Frequency)", fontsize=20)
43+
ax.set_title("bar-categorical · matplotlib · pyplots.ai", fontsize=24)
44+
ax.tick_params(axis="both", labelsize=16)
45+
ax.grid(True, axis="y", alpha=0.3, linestyle="--")
46+
47+
# Remove top and right spines for cleaner look
48+
ax.spines["top"].set_visible(False)
49+
ax.spines["right"].set_visible(False)
50+
51+
plt.tight_layout()
52+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
library: matplotlib
2+
specification_id: bar-categorical
3+
created: '2025-12-30T11:22:26Z'
4+
updated: '2025-12-30T11:29:47Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20595333486
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 3.10.8
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/bar-categorical/matplotlib/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bar-categorical/matplotlib/plot_thumb.png
12+
preview_html: null
13+
quality_score: 94
14+
review:
15+
strengths:
16+
- Excellent text legibility with appropriate font sizes for 4800x2700 output
17+
- Clean KISS code structure following the imports → data → plot → save pattern
18+
- Realistic survey data scenario with varied frequency distribution
19+
- Proper descending sort as suggested in the specification
20+
- Value labels on bars enhance readability and data communication
21+
- Professional appearance with removed top/right spines and subtle grid
22+
weaknesses:
23+
- Could use more distinctive matplotlib features (e.g., custom hatching, gradient
24+
fills, or annotation arrows)
25+
- Y-axis label "Count (Frequency)" is slightly redundant - could be simplified

0 commit comments

Comments
 (0)