Skip to content

Commit f15682b

Browse files
Merge branch 'main' into implementation/line-basic/letsplot
2 parents 6a09d90 + 49f5a4b commit f15682b

12 files changed

Lines changed: 1212 additions & 868 deletions

File tree

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,70 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
line-basic: Basic Line Plot
3-
Library: altair 6.0.0 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: altair 6.1.0 | Python 3.13.13
4+
Quality: 86/100 | Updated: 2026-04-29
55
"""
66

7+
import os
8+
79
import altair as alt
810
import numpy as np
911
import pandas as pd
1012

1113

14+
# Theme tokens
15+
THEME = os.getenv("ANYPLOT_THEME", "light")
16+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
17+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
18+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
19+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
20+
BRAND = "#009E73"
21+
1222
# Data - Monthly temperature readings over a year
1323
np.random.seed(42)
1424
months = pd.date_range(start="2024-01-01", periods=12, freq="MS")
15-
# Simulate temperature pattern (cold in winter, warm in summer)
1625
base_temp = 15 + 12 * np.sin((np.arange(12) - 3) * np.pi / 6)
1726
temperature = base_temp + np.random.randn(12) * 2
18-
1927
df = pd.DataFrame({"Month": months, "Temperature": temperature})
2028

2129
# Plot
22-
chart = (
30+
tooltip_enc = [
31+
alt.Tooltip("Month:T", title="Month", format="%B %Y"),
32+
alt.Tooltip("Temperature:Q", title="Temperature (°C)", format=".1f"),
33+
]
34+
35+
line = (
2336
alt.Chart(df)
24-
.mark_line(strokeWidth=4, color="#306998")
25-
.encode(
26-
x=alt.X("Month:T", title="Month", axis=alt.Axis(labelFontSize=18, titleFontSize=22)),
27-
y=alt.Y("Temperature:Q", title="Temperature (°C)", axis=alt.Axis(labelFontSize=18, titleFontSize=22)),
28-
)
29-
.properties(width=1600, height=900, title=alt.Title("line-basic · altair · pyplots.ai", fontSize=28))
37+
.mark_line(strokeWidth=4, color=BRAND)
38+
.encode(x=alt.X("Month:T", title="Month"), y=alt.Y("Temperature:Q", title="Temperature (°C)"))
3039
)
3140

32-
# Add points to enhance visibility
33-
points = alt.Chart(df).mark_point(size=200, color="#306998", filled=True).encode(x="Month:T", y="Temperature:Q")
41+
points = (
42+
alt.Chart(df)
43+
.mark_point(size=200, color=BRAND, filled=True)
44+
.encode(x="Month:T", y="Temperature:Q", tooltip=tooltip_enc)
45+
)
3446

35-
# Combine line and points with subtle grid
36-
final_chart = (chart + points).configure_axis(gridColor="#E0E0E0", gridOpacity=0.3).configure_view(strokeWidth=0)
47+
chart = (
48+
(line + points)
49+
.interactive()
50+
.properties(
51+
width=1600, height=900, title=alt.Title("line-basic · altair · anyplot.ai", fontSize=28), background=PAGE_BG
52+
)
53+
.configure_view(fill=PAGE_BG, stroke=INK_SOFT)
54+
.configure_axis(
55+
domainColor=INK_SOFT,
56+
tickColor=INK_SOFT,
57+
gridColor=INK,
58+
gridOpacity=0.15,
59+
labelColor=INK_SOFT,
60+
titleColor=INK,
61+
labelFontSize=18,
62+
titleFontSize=22,
63+
)
64+
.configure_title(color=INK, fontSize=28)
65+
.configure_legend(fillColor=ELEVATED_BG, strokeColor=INK_SOFT, labelColor=INK_SOFT, titleColor=INK)
66+
)
3767

3868
# Save
39-
final_chart.save("plot.png", scale_factor=3.0)
40-
final_chart.save("plot.html")
69+
chart.save(f"plot-{THEME}.png", scale_factor=3.0)
70+
chart.save(f"plot-{THEME}.html")
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")

0 commit comments

Comments
 (0)