Skip to content

Commit 9273575

Browse files
Merge branch 'main' into implementation/line-basic/altair
2 parents 4da745d + b523eb5 commit 9273575

10 files changed

Lines changed: 1008 additions & 725 deletions

File tree

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,77 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
line-basic: Basic Line Plot
3-
Library: bokeh 3.8.1 | Python 3.13.11
4-
Quality: 92/100 | Created: 2025-12-23
3+
Library: bokeh 3.9.0 | Python 3.13.13
4+
Quality: 87/100 | Updated: 2026-04-29
55
"""
66

7+
import os
8+
79
import numpy as np
810
from bokeh.io import export_png, output_file, save
911
from bokeh.models import ColumnDataSource
1012
from bokeh.plotting import figure
1113

1214

15+
# Theme tokens
16+
THEME = os.getenv("ANYPLOT_THEME", "light")
17+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
18+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
19+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
20+
BRAND = "#009E73"
21+
1322
# Data - Daily temperature readings for a month
1423
np.random.seed(42)
1524
days = np.arange(1, 32)
25+
base_temp = 20 + 8 * np.sin(np.linspace(0, np.pi, 31))
26+
temperature = base_temp + np.random.randn(31) * 2
1627

17-
# Temperature with seasonal pattern and random variation
18-
base_temp = 20 + 8 * np.sin(np.linspace(0, np.pi, 31)) # Warm mid-month
19-
noise = np.random.randn(31) * 2
20-
temperature = base_temp + noise
21-
22-
# Create ColumnDataSource
2328
source = ColumnDataSource(data={"day": days, "temperature": temperature})
2429

25-
# Create figure (4800 × 2700 px)
30+
# Plot
2631
p = figure(
2732
width=4800,
2833
height=2700,
29-
title="line-basic · bokeh · pyplots.ai",
34+
title="line-basic · bokeh · anyplot.ai",
3035
x_axis_label="Day of Month",
3136
y_axis_label="Temperature (°C)",
3237
)
3338

34-
# Plot line with markers for visibility
35-
p.line(x="day", y="temperature", source=source, line_width=5, line_color="#306998")
36-
p.scatter(x="day", y="temperature", source=source, size=16, fill_color="#306998", line_color="white", line_width=3)
39+
p.line(x="day", y="temperature", source=source, line_width=5, line_color=BRAND)
40+
p.scatter(x="day", y="temperature", source=source, size=16, fill_color=BRAND, line_color=PAGE_BG, line_width=3)
3741

38-
# Style text sizes for 4800x2700 px
42+
# Style text sizes for 4800×2700 px
3943
p.title.text_font_size = "42pt"
44+
p.title.text_color = INK
4045
p.xaxis.axis_label_text_font_size = "32pt"
46+
p.xaxis.axis_label_text_color = INK
4147
p.yaxis.axis_label_text_font_size = "32pt"
48+
p.yaxis.axis_label_text_color = INK
4249
p.xaxis.major_label_text_font_size = "24pt"
50+
p.xaxis.major_label_text_color = INK_SOFT
4351
p.yaxis.major_label_text_font_size = "24pt"
52+
p.yaxis.major_label_text_color = INK_SOFT
4453

45-
# Grid styling - subtle dashed lines
46-
p.grid.grid_line_alpha = 0.3
47-
p.grid.grid_line_dash = "dashed"
54+
# Background and borders
55+
p.background_fill_color = PAGE_BG
56+
p.border_fill_color = PAGE_BG
57+
p.outline_line_color = INK_SOFT
4858

49-
# Background styling
50-
p.background_fill_color = "#fafafa"
51-
p.border_fill_color = "white"
59+
# Axis lines and ticks
60+
p.xaxis.axis_line_color = INK_SOFT
61+
p.yaxis.axis_line_color = INK_SOFT
62+
p.xaxis.major_tick_line_color = INK_SOFT
63+
p.yaxis.major_tick_line_color = INK_SOFT
64+
p.xaxis.axis_line_width = 2
65+
p.yaxis.axis_line_width = 2
5266

53-
# Axis styling
54-
p.axis.axis_line_width = 2
55-
p.axis.axis_line_color = "#333333"
56-
p.axis.major_tick_line_width = 2
57-
p.axis.minor_tick_line_width = 1
67+
# Grid — y-axis only, subtle
68+
p.xgrid.grid_line_color = None
69+
p.ygrid.grid_line_color = INK
70+
p.ygrid.grid_line_alpha = 0.10
5871

59-
# Remove toolbar for cleaner static image
6072
p.toolbar_location = None
6173

62-
# Save as PNG and HTML
63-
export_png(p, filename="plot.png")
64-
65-
output_file("plot.html")
74+
# Save
75+
export_png(p, filename=f"plot-{THEME}.png")
76+
output_file(f"plot-{THEME}.html")
6677
save(p)
Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,118 @@
11
""" anyplot.ai
22
line-basic: Basic Line Plot
3-
Library: plotly 6.7.0 | Python 3.14.4
4-
Quality: 82/100 | Updated: 2026-04-29
3+
Library: plotly 6.7.0 | Python 3.13.13
4+
Quality: 92/100 | Updated: 2026-04-29
55
"""
66

7+
import os
8+
79
import numpy as np
810
import plotly.graph_objects as go
911

1012

11-
# Data - Monthly temperature readings
13+
# Theme tokens
14+
THEME = os.getenv("ANYPLOT_THEME", "light")
15+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
16+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
17+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
18+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
19+
GRID = "rgba(26,26,23,0.10)" if THEME == "light" else "rgba(240,239,232,0.10)"
20+
BRAND = "#009E73"
21+
BRAND_FILL = "rgba(0,158,115,0.12)"
22+
23+
# Data - Monthly temperature readings (seasonal pattern)
1224
np.random.seed(42)
1325
months = np.arange(1, 13)
14-
# Simulate temperature pattern (cold winter, warm summer)
26+
month_labels = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
1527
temperature = 15 + 12 * np.sin((months - 4) * np.pi / 6) + np.random.randn(12) * 1.5
1628

17-
# Create figure
29+
peak_idx = int(np.argmax(temperature))
30+
31+
# Plot
1832
fig = go.Figure()
1933

2034
fig.add_trace(
2135
go.Scatter(
2236
x=months,
2337
y=temperature,
2438
mode="lines+markers",
25-
line={"color": "#306998", "width": 5},
26-
marker={"size": 18, "color": "#306998"},
27-
hovertemplate="Month: %{x}<br>Temperature: %{y:.1f}°C<extra></extra>",
39+
line={"color": BRAND, "width": 5},
40+
marker={"size": 18, "color": BRAND},
41+
fill="tozeroy",
42+
fillcolor=BRAND_FILL,
43+
hovertemplate="%{customdata}<br>%{y:.1f}°C<extra></extra>",
44+
customdata=month_labels,
2845
)
2946
)
3047

31-
# Layout
48+
# Peak annotation for visual storytelling
49+
fig.add_annotation(
50+
x=months[peak_idx],
51+
y=temperature[peak_idx],
52+
text=f"Peak: {temperature[peak_idx]:.1f}°C",
53+
showarrow=True,
54+
arrowhead=2,
55+
arrowcolor=INK_SOFT,
56+
arrowwidth=2,
57+
ax=40,
58+
ay=-50,
59+
font={"size": 20, "color": INK},
60+
bgcolor=ELEVATED_BG,
61+
bordercolor=INK_SOFT,
62+
borderwidth=1,
63+
borderpad=6,
64+
)
65+
3266
fig.update_layout(
33-
title={"text": "line-basic · plotly · pyplots.ai", "font": {"size": 40}, "x": 0.5, "xanchor": "center"},
67+
paper_bgcolor=PAGE_BG,
68+
plot_bgcolor=PAGE_BG,
69+
font={"color": INK},
70+
title={
71+
"text": "line-basic · plotly · anyplot.ai",
72+
"font": {"size": 36, "color": INK},
73+
"x": 0.5,
74+
"xanchor": "center",
75+
},
3476
xaxis={
35-
"title": {"text": "Month", "font": {"size": 36}},
36-
"tickfont": {"size": 28},
77+
"title": {"text": "Month", "font": {"size": 28, "color": INK}},
78+
"tickfont": {"size": 22, "color": INK_SOFT},
3779
"tickmode": "array",
3880
"tickvals": months,
39-
"ticktext": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
81+
"ticktext": month_labels,
4082
"showgrid": True,
4183
"gridwidth": 1,
42-
"gridcolor": "rgba(0,0,0,0.1)",
84+
"gridcolor": GRID,
85+
"showline": True,
86+
"linecolor": INK_SOFT,
87+
"mirror": False,
88+
"zerolinecolor": GRID,
89+
"showspikes": True,
90+
"spikemode": "across",
91+
"spikethickness": 1,
92+
"spikedash": "dot",
93+
"spikecolor": INK_SOFT,
4394
},
4495
yaxis={
45-
"title": {"text": "Temperature (°C)", "font": {"size": 36}},
46-
"tickfont": {"size": 28},
96+
"title": {"text": "Temperature (°C)", "font": {"size": 28, "color": INK}},
97+
"tickfont": {"size": 22, "color": INK_SOFT},
4798
"showgrid": True,
4899
"gridwidth": 1,
49-
"gridcolor": "rgba(0,0,0,0.1)",
100+
"gridcolor": GRID,
101+
"showline": True,
102+
"linecolor": INK_SOFT,
103+
"mirror": False,
104+
"zerolinecolor": GRID,
105+
"rangemode": "tozero",
106+
"showspikes": True,
107+
"spikemode": "across",
108+
"spikethickness": 1,
109+
"spikedash": "dot",
110+
"spikecolor": INK_SOFT,
50111
},
51-
template="plotly_white",
52-
margin={"t": 120, "b": 100, "l": 120, "r": 50},
112+
hovermode="x",
113+
margin={"t": 120, "b": 100, "l": 120, "r": 60},
53114
)
54115

55116
# Save
56-
fig.write_image("plot.png", width=1600, height=900, scale=3)
57-
fig.write_html("plot.html")
117+
fig.write_image(f"plot-{THEME}.png", width=1600, height=900, scale=3)
118+
fig.write_html(f"plot-{THEME}.html", include_plotlyjs="cdn")
Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
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
55
"""
66

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+
714
import numpy as np
815
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+
1030

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"
1137

1238
# Data - Monthly average temperature readings for a typical year
1339
np.random.seed(42)
@@ -17,22 +43,27 @@
1743

1844
df = pd.DataFrame({"Month": months, "Temperature": temperature})
1945

46+
month_labels = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
47+
2048
# Plot
2149
plot = (
2250
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")
2655
+ theme_minimal()
2756
+ theme(
2857
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),
3566
)
3667
)
3768

38-
plot.save("plot.png", dpi=300, verbose=False)
69+
plot.save(f"plot-{THEME}.png", dpi=300, verbose=False)

0 commit comments

Comments
 (0)