|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | line-basic: Basic Line Plot |
3 | | -Library: plotnine 0.15.2 | Python 3.13.11 |
4 | | -Quality: 91/100 | Created: 2025-12-23 |
| 3 | +Library: plotnine 0.15.3 | Python 3.13.13 |
| 4 | +Quality: 89/100 | Updated: 2026-04-29 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | +import sys |
| 9 | + |
| 10 | + |
| 11 | +# Prevent this file from shadowing the plotnine library when run from its own directory |
| 12 | +sys.path = [p for p in sys.path if not p or os.path.abspath(p) != os.path.abspath(os.path.dirname(__file__))] |
| 13 | + |
7 | 14 | import numpy as np |
8 | 15 | import pandas as pd |
9 | | -from plotnine import aes, element_line, element_text, geom_line, geom_point, ggplot, labs, theme, theme_minimal |
| 16 | +from plotnine import ( |
| 17 | + aes, |
| 18 | + element_line, |
| 19 | + element_rect, |
| 20 | + element_text, |
| 21 | + geom_line, |
| 22 | + geom_point, |
| 23 | + ggplot, |
| 24 | + labs, |
| 25 | + scale_x_continuous, |
| 26 | + theme, |
| 27 | + theme_minimal, |
| 28 | +) |
| 29 | + |
10 | 30 |
|
| 31 | +# Theme tokens |
| 32 | +THEME = os.getenv("ANYPLOT_THEME", "light") |
| 33 | +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 34 | +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
| 35 | +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 36 | +BRAND = "#009E73" |
11 | 37 |
|
12 | 38 | # Data - Monthly average temperature readings for a typical year |
13 | 39 | np.random.seed(42) |
|
17 | 43 |
|
18 | 44 | df = pd.DataFrame({"Month": months, "Temperature": temperature}) |
19 | 45 |
|
| 46 | +month_labels = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] |
| 47 | + |
20 | 48 | # Plot |
21 | 49 | plot = ( |
22 | 50 | ggplot(df, aes(x="Month", y="Temperature")) |
23 | | - + geom_line(size=2.5, color="#306998") |
24 | | - + geom_point(size=6, color="#306998") |
25 | | - + labs(x="Month", y="Temperature (°C)", title="line-basic · plotnine · pyplots.ai") |
| 51 | + + geom_line(size=2.5, color=BRAND) |
| 52 | + + geom_point(size=6, color=BRAND) |
| 53 | + + scale_x_continuous(breaks=list(range(1, 13)), labels=month_labels) |
| 54 | + + labs(x="Month", y="Temperature (°C)", title="line-basic · plotnine · anyplot.ai") |
26 | 55 | + theme_minimal() |
27 | 56 | + theme( |
28 | 57 | figure_size=(16, 9), |
29 | | - text=element_text(size=14), |
30 | | - axis_title=element_text(size=20), |
31 | | - axis_text=element_text(size=16), |
32 | | - plot_title=element_text(size=24), |
33 | | - panel_grid_major=element_line(color="#cccccc", size=0.5, alpha=0.3), |
34 | | - panel_grid_minor=element_line(color="#eeeeee", size=0.3, alpha=0.2), |
| 58 | + plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
| 59 | + panel_background=element_rect(fill=PAGE_BG), |
| 60 | + text=element_text(size=14, color=INK), |
| 61 | + axis_title=element_text(size=20, color=INK), |
| 62 | + axis_text=element_text(size=16, color=INK_SOFT), |
| 63 | + plot_title=element_text(size=24, color=INK), |
| 64 | + panel_grid_major=element_line(color=INK_SOFT, size=0.3, alpha=0.15), |
| 65 | + panel_grid_minor=element_line(color=INK_SOFT, size=0.2, alpha=0.05), |
35 | 66 | ) |
36 | 67 | ) |
37 | 68 |
|
38 | | -plot.save("plot.png", dpi=300, verbose=False) |
| 69 | +plot.save(f"plot-{THEME}.png", dpi=300, verbose=False) |
0 commit comments