|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | lollipop-basic: Basic Lollipop Chart |
3 | | -Library: plotnine 0.15.2 | Python 3.13.11 |
4 | | -Quality: 92/100 | Created: 2025-12-23 |
| 3 | +Library: plotnine 0.15.3 | Python 3.14.4 |
| 4 | +Quality: 85/100 | Updated: 2026-04-26 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import pandas as pd |
8 | | -from plotnine import aes, element_line, element_text, geom_point, geom_segment, ggplot, labs, theme, theme_minimal |
| 10 | +from plotnine import ( |
| 11 | + aes, |
| 12 | + element_line, |
| 13 | + element_rect, |
| 14 | + element_text, |
| 15 | + geom_point, |
| 16 | + geom_segment, |
| 17 | + ggplot, |
| 18 | + ggsave, |
| 19 | + labs, |
| 20 | + theme, |
| 21 | + theme_minimal, |
| 22 | +) |
| 23 | + |
9 | 24 |
|
| 25 | +THEME = os.getenv("ANYPLOT_THEME", "light") |
| 26 | +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 27 | +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
| 28 | +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 29 | +BRAND = "#009E73" |
10 | 30 |
|
11 | 31 | # Data - Product sales by category, sorted by value |
12 | 32 | data = { |
|
32 | 52 | # Plot |
33 | 53 | plot = ( |
34 | 54 | ggplot(df, aes(x="category", y="value")) |
35 | | - # Stems - thin lines from baseline to value |
36 | | - + geom_segment(aes(x="category", xend="category", y=0, yend="value"), color="#306998", size=1.5) |
37 | | - # Circular markers at data values |
38 | | - + geom_point(color="#306998", size=6, fill="#306998") |
39 | | - + labs(x="Product Category", y="Sales (thousands $)", title="lollipop-basic · plotnine · pyplots.ai") |
| 55 | + + geom_segment(aes(x="category", xend="category", y=0, yend="value"), color=BRAND, size=1.5) |
| 56 | + + geom_point(color=BRAND, size=6, fill=BRAND) |
| 57 | + + labs(x="Product Category", y="Sales (thousands $)", title="lollipop-basic · plotnine · anyplot.ai") |
40 | 58 | + theme_minimal() |
41 | 59 | + theme( |
42 | 60 | figure_size=(16, 9), |
43 | | - text=element_text(size=14), |
44 | | - axis_title=element_text(size=20), |
45 | | - axis_text=element_text(size=16), |
46 | | - axis_text_x=element_text(angle=45, ha="right"), |
47 | | - plot_title=element_text(size=24), |
| 61 | + plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
| 62 | + panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
| 63 | + text=element_text(size=14, color=INK), |
| 64 | + axis_title=element_text(size=20, color=INK), |
| 65 | + axis_text=element_text(size=16, color=INK_SOFT), |
| 66 | + axis_text_x=element_text(angle=45, ha="right", color=INK_SOFT), |
| 67 | + axis_line=element_line(color=INK_SOFT), |
| 68 | + plot_title=element_text(size=24, color=INK), |
48 | 69 | panel_grid_minor=element_line(alpha=0), |
49 | 70 | panel_grid_major_x=element_line(alpha=0), |
50 | | - panel_grid_major_y=element_line(alpha=0.3, linetype="dashed"), |
| 71 | + panel_grid_major_y=element_line(color=INK, alpha=0.15, size=0.3), |
51 | 72 | ) |
52 | 73 | ) |
53 | 74 |
|
54 | | -plot.save("plot.png", dpi=300) |
| 75 | +ggsave(plot, filename=f"plot-{THEME}.png", dpi=300, width=16, height=9) |
0 commit comments