Skip to content

Commit a5ee8a2

Browse files
feat(pygal): implement bar-sorted (#2582)
## Implementation: `bar-sorted` - pygal Implements the **pygal** version of `bar-sorted`. **File:** `plots/bar-sorted/implementations/pygal.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20593352116)* --------- 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 4242f85 commit a5ee8a2

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
""" pyplots.ai
2+
bar-sorted: Sorted Bar Chart
3+
Library: pygal 3.1.0 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-30
5+
"""
6+
7+
import pygal
8+
from pygal.style import Style
9+
10+
11+
# Data - Monthly sales by product category (already sorted descending)
12+
categories = ["Electronics", "Clothing", "Home & Garden", "Sports", "Books", "Toys", "Beauty", "Food"]
13+
values = [4850, 3720, 2980, 2450, 1890, 1560, 1240, 980]
14+
15+
# Reverse for pygal HorizontalBar (renders bottom-to-top, so largest should be last)
16+
categories_reversed = list(reversed(categories))
17+
values_reversed = list(reversed(values))
18+
19+
# Custom style for 4800x2700 canvas with increased font sizes
20+
custom_style = Style(
21+
background="white",
22+
plot_background="white",
23+
foreground="#333333",
24+
foreground_strong="#333333",
25+
foreground_subtle="#999999", # Lighter color for grid lines
26+
colors=("#306998",), # Python Blue for all bars
27+
title_font_size=84,
28+
label_font_size=56,
29+
major_label_font_size=50,
30+
legend_font_size=50,
31+
value_font_size=44,
32+
value_label_font_size=44,
33+
tooltip_font_size=44,
34+
stroke_width=2,
35+
)
36+
37+
# Create horizontal bar chart (better for category labels)
38+
chart = pygal.HorizontalBar(
39+
width=4800,
40+
height=2700,
41+
style=custom_style,
42+
title="bar-sorted · pygal · pyplots.ai",
43+
x_title="Sales (USD)",
44+
show_legend=False,
45+
show_x_guides=True,
46+
print_values=True,
47+
print_values_position="center",
48+
value_formatter=lambda x: f"${x:,.0f}",
49+
margin=80,
50+
spacing=30,
51+
truncate_label=-1,
52+
)
53+
54+
# Set category labels on Y-axis (x_labels maps to Y-axis in HorizontalBar)
55+
chart.x_labels = categories_reversed
56+
57+
# Add data as single series (no legend needed since x_labels provide categories)
58+
chart.add("Sales", values_reversed)
59+
60+
# Save as PNG and HTML
61+
chart.render_to_png("plot.png")
62+
chart.render_to_file("plot.html")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
library: pygal
2+
specification_id: bar-sorted
3+
created: '2025-12-30T09:32:30Z'
4+
updated: '2025-12-30T10:01:42Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20593352116
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 3.1.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/bar-sorted/pygal/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bar-sorted/pygal/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/bar-sorted/pygal/plot.html
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent sorting implementation with proper reversal for pygal bottom-to-top
17+
rendering
18+
- Clean, readable code structure following KISS principles
19+
- Good use of pygal custom Style for consistent theming at high resolution
20+
- Value labels centered in bars with proper currency formatting
21+
- Horizontal orientation is ideal for category labels as noted in spec
22+
- Appropriate font sizes scaled for 4800x2700 canvas
23+
weaknesses:
24+
- Missing y-axis title to label the categories dimension
25+
- Data values could show more variation to better demonstrate sorting benefit

0 commit comments

Comments
 (0)