Skip to content

Commit 1c160c3

Browse files
feat(pygal): implement bar-diverging (#6032)
## Implementation: `bar-diverging` - python/pygal Implements the **python/pygal** version of `bar-diverging`. **File:** `plots/bar-diverging/implementations/python/pygal.py` **Parent Issue:** #2009 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25546666197)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Markus Neusinger <2921697+MarkusNeusinger@users.noreply.github.com>
1 parent 07b8e8e commit 1c160c3

2 files changed

Lines changed: 188 additions & 156 deletions

File tree

plots/bar-diverging/implementations/python/pygal.py

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
bar-diverging: Diverging Bar Chart
3-
Library: pygal 3.1.0 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-25
3+
Library: pygal 3.1.0 | Python 3.13.13
4+
Quality: 93/100 | Updated: 2026-05-08
55
"""
66

7+
import os
8+
import sys
9+
10+
11+
if sys.path[0] == os.path.dirname(os.path.abspath(__file__)):
12+
sys.path.pop(0)
13+
714
import pygal
815
from pygal.style import Style
916

1017

18+
# Theme tokens from prompts/default-style-guide.md
19+
THEME = os.getenv("ANYPLOT_THEME", "light")
20+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
21+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
22+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
23+
INK_MUTED = "#6B6A63" if THEME == "light" else "#A8A79F"
24+
25+
# Okabe-Ito palette: brand green for positive, vermillion for negative
26+
OKABE_ITO = ("#009E73", "#D55E00")
27+
1128
# Data - Customer satisfaction survey scores by department
1229
# Positive = satisfied, Negative = dissatisfied (scale -100 to +100)
1330
departments = [
@@ -23,38 +40,37 @@
2340
"Overall Experience",
2441
]
2542

26-
# Survey scores (positive = satisfied, negative = dissatisfied)
2743
scores = [72, 45, -23, 58, -45, 31, -12, -38, 64, 52]
2844

2945
# Sort by value for better pattern recognition
3046
sorted_data = sorted(zip(departments, scores, strict=True), key=lambda x: x[1])
3147
sorted_departments = [d[0] for d in sorted_data]
3248
sorted_scores = [d[1] for d in sorted_data]
3349

34-
# Custom style for pyplots
35-
# Using blue for positive and red/coral for negative (better contrast for diverging)
50+
# Custom style with theme-adaptive colors and proper font sizing
3651
custom_style = Style(
37-
background="white",
38-
plot_background="white",
39-
foreground="#333333",
40-
foreground_strong="#333333",
41-
foreground_subtle="#666666",
42-
colors=("#306998", "#E07A5F"), # Python Blue for positive, Coral for negative
43-
title_font_size=72,
44-
label_font_size=48,
45-
major_label_font_size=42,
46-
legend_font_size=42,
47-
value_font_size=36,
48-
value_label_font_size=36,
49-
tooltip_font_size=36,
52+
background=PAGE_BG,
53+
plot_background=PAGE_BG,
54+
foreground=INK,
55+
foreground_strong=INK,
56+
foreground_subtle=INK_MUTED,
57+
colors=OKABE_ITO,
58+
title_font_size=28,
59+
label_font_size=22,
60+
major_label_font_size=18,
61+
legend_font_size=16,
62+
value_font_size=14,
63+
value_label_font_size=14,
64+
tooltip_font_size=14,
65+
stroke_width=2,
5066
)
5167

5268
# Create horizontal bar chart (better for long labels)
5369
chart = pygal.HorizontalBar(
5470
width=4800,
5571
height=2700,
5672
style=custom_style,
57-
title="Customer Satisfaction Survey · bar-diverging · pygal · pyplots.ai",
73+
title="Customer Satisfaction Survey · bar-diverging · pygal · anyplot.ai",
5874
x_title="Satisfaction Score",
5975
show_legend=True,
6076
legend_at_bottom=True,
@@ -80,6 +96,7 @@
8096
# Set category labels
8197
chart.x_labels = sorted_departments
8298

83-
# Save outputs
84-
chart.render_to_png("plot.png")
85-
chart.render_to_file("plot.html")
99+
# Save outputs with theme-suffixed filenames
100+
chart.render_to_png(f"plot-{THEME}.png")
101+
with open(f"plot-{THEME}.html", "wb") as f:
102+
f.write(chart.render())

0 commit comments

Comments
 (0)