|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | 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 |
5 | 5 | """ |
6 | 6 |
|
| 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 | + |
7 | 14 | import pygal |
8 | 15 | from pygal.style import Style |
9 | 16 |
|
10 | 17 |
|
| 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 | + |
11 | 28 | # Data - Customer satisfaction survey scores by department |
12 | 29 | # Positive = satisfied, Negative = dissatisfied (scale -100 to +100) |
13 | 30 | departments = [ |
|
23 | 40 | "Overall Experience", |
24 | 41 | ] |
25 | 42 |
|
26 | | -# Survey scores (positive = satisfied, negative = dissatisfied) |
27 | 43 | scores = [72, 45, -23, 58, -45, 31, -12, -38, 64, 52] |
28 | 44 |
|
29 | 45 | # Sort by value for better pattern recognition |
30 | 46 | sorted_data = sorted(zip(departments, scores, strict=True), key=lambda x: x[1]) |
31 | 47 | sorted_departments = [d[0] for d in sorted_data] |
32 | 48 | sorted_scores = [d[1] for d in sorted_data] |
33 | 49 |
|
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 |
36 | 51 | 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, |
50 | 66 | ) |
51 | 67 |
|
52 | 68 | # Create horizontal bar chart (better for long labels) |
53 | 69 | chart = pygal.HorizontalBar( |
54 | 70 | width=4800, |
55 | 71 | height=2700, |
56 | 72 | style=custom_style, |
57 | | - title="Customer Satisfaction Survey · bar-diverging · pygal · pyplots.ai", |
| 73 | + title="Customer Satisfaction Survey · bar-diverging · pygal · anyplot.ai", |
58 | 74 | x_title="Satisfaction Score", |
59 | 75 | show_legend=True, |
60 | 76 | legend_at_bottom=True, |
|
80 | 96 | # Set category labels |
81 | 97 | chart.x_labels = sorted_departments |
82 | 98 |
|
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