Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 55 additions & 27 deletions plots/line-basic/implementations/python/letsplot.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,75 @@
""" pyplots.ai
""" anyplot.ai
line-basic: Basic Line Plot
Library: letsplot 4.8.1 | Python 3.13.11
Quality: 92/100 | Created: 2025-12-23
Library: letsplot 4.9.0 | Python 3.13.13
Quality: 88/100 | Updated: 2026-04-29
"""

import os

import numpy as np
import pandas as pd
from lets_plot import * # noqa: F403
from lets_plot.export import ggsave as export_ggsave
from lets_plot import (
LetsPlot,
aes,
element_blank,
element_line,
element_rect,
element_text,
geom_line,
geom_point,
ggplot,
ggsize,
labs,
scale_x_continuous,
theme,
theme_minimal,
)
from lets_plot.export import ggsave


LetsPlot.setup_html()

LetsPlot.setup_html() # noqa: F405
# Theme tokens
THEME = os.getenv("ANYPLOT_THEME", "light")
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
RULE = "rgba(26,26,23,0.12)" if THEME == "light" else "rgba(240,239,232,0.12)"
BRAND = "#009E73"

# Data - Monthly temperature readings over a year
np.random.seed(42)
months = np.arange(1, 13)
# Simulate temperature pattern: warmer in summer, cooler in winter
base_temp = 15 + 12 * np.sin((months - 4) * np.pi / 6)
temperature = base_temp + np.random.randn(12) * 1.5

df = pd.DataFrame({"month": months, "temperature": temperature})

# Plot
plot = (
ggplot(df, aes(x="month", y="temperature")) # noqa: F405
+ geom_line(color="#306998", size=2) # noqa: F405
+ geom_point(color="#306998", size=5, alpha=0.8) # noqa: F405
+ labs( # noqa: F405
x="Month", y="Temperature (°C)", title="line-basic · letsplot · pyplots.ai"
)
+ scale_x_continuous(breaks=list(range(1, 13))) # noqa: F405
+ ggsize(1600, 900) # noqa: F405
+ theme_minimal() # noqa: F405
+ theme( # noqa: F405
axis_text=element_text(size=16), # noqa: F405
axis_title=element_text(size=20), # noqa: F405
plot_title=element_text(size=24), # noqa: F405
panel_grid=element_line(color="#CCCCCC", size=0.5, linetype="dashed"), # noqa: F405
)
anyplot_theme = theme(
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
panel_background=element_rect(fill=PAGE_BG),
panel_grid_major_y=element_line(color=RULE, size=0.5),
panel_grid_major_x=element_blank(),
panel_grid_minor=element_blank(),
axis_title=element_text(color=INK, size=20),
axis_text=element_text(color=INK_SOFT, size=16),
axis_line=element_line(color=INK_SOFT),
plot_title=element_text(color=INK, size=24),
)

# Save PNG (scale 3x to get 4800 x 2700 px)
export_ggsave(plot, "plot.png", path=".", scale=3)
plot = (
ggplot(df, aes(x="month", y="temperature"))
+ geom_line(color=BRAND, size=2)
+ geom_point(color=BRAND, size=5, alpha=0.9)
+ labs(x="Month", y="Temperature (°C)", title="line-basic · letsplot · anyplot.ai")
+ scale_x_continuous(breaks=list(range(1, 13)))
+ ggsize(1600, 900)
+ theme_minimal()
+ anyplot_theme
)

# Save HTML for interactive version
export_ggsave(plot, "plot.html", path=".")
# Save
ggsave(plot, f"plot-{THEME}.png", path=".", scale=3)
ggsave(plot, f"plot-{THEME}.html", path=".")
Loading
Loading