Skip to content

Commit 62b15da

Browse files
feat(plotnine): implement bar-categorical (#2659)
## Implementation: `bar-categorical` - plotnine Implements the **plotnine** version of `bar-categorical`. **File:** `plots/bar-categorical/implementations/plotnine.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20595336970)* --------- 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 c5cb1cd commit 62b15da

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
""" pyplots.ai
2+
bar-categorical: Categorical Count Bar Chart
3+
Library: plotnine 0.15.2 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import pandas as pd
9+
from plotnine import aes, element_blank, element_text, geom_bar, ggplot, labs, scale_fill_manual, theme, theme_minimal
10+
11+
12+
# Data - Survey responses for product satisfaction
13+
np.random.seed(42)
14+
categories = ["Excellent", "Good", "Average", "Poor", "Very Poor"]
15+
# Create uneven distribution to show varying counts
16+
weights = [0.25, 0.35, 0.20, 0.12, 0.08]
17+
n_responses = 200
18+
responses = np.random.choice(categories, size=n_responses, p=weights)
19+
20+
df = pd.DataFrame({"Satisfaction": responses})
21+
22+
# Reorder categories for logical display
23+
df["Satisfaction"] = pd.Categorical(df["Satisfaction"], categories=categories, ordered=True)
24+
25+
# Plot
26+
plot = (
27+
ggplot(df, aes(x="Satisfaction", fill="Satisfaction"))
28+
+ geom_bar(width=0.7, alpha=0.9)
29+
+ labs(x="Satisfaction Level", y="Number of Responses", title="bar-categorical · plotnine · pyplots.ai")
30+
+ scale_fill_manual(values=["#306998", "#4A90C2", "#FFD43B", "#E8A838", "#CC6633"])
31+
+ theme_minimal()
32+
+ theme(
33+
figure_size=(16, 9),
34+
text=element_text(size=14),
35+
axis_title=element_text(size=20),
36+
axis_text=element_text(size=16),
37+
plot_title=element_text(size=24),
38+
legend_position="none",
39+
panel_grid_major_x=element_blank(),
40+
)
41+
)
42+
43+
# Save
44+
plot.save("plot.png", dpi=300, verbose=False)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
library: plotnine
2+
specification_id: bar-categorical
3+
created: '2025-12-30T11:22:13Z'
4+
updated: '2025-12-30T11:28:59Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20595336970
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 0.15.2
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/bar-categorical/plotnine/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bar-categorical/plotnine/plot_thumb.png
12+
preview_html: null
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent use of plotnine grammar of graphics with geom_bar() for automatic count
17+
computation
18+
- Smart use of pd.Categorical to enforce logical ordering of satisfaction levels
19+
- Clean, publication-quality visual design with appropriate font sizes for 4800x2700
20+
resolution
21+
- Good choice of diverging color palette that semantically matches satisfaction
22+
levels (blue=good, orange=poor)
23+
- Proper KISS code structure with reproducible seed
24+
weaknesses:
25+
- Could use scale_fill_brewer() with a diverging palette instead of manual colors
26+
for better colorblind accessibility
27+
- Missing count annotations on bars which would enhance readability

0 commit comments

Comments
 (0)