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
69 changes: 48 additions & 21 deletions plots/line-timeseries/implementations/python/letsplot.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,74 @@
""" pyplots.ai
""" anyplot.ai
line-timeseries: Time Series Line Plot
Library: letsplot 4.8.2 | Python 3.13.11
Quality: 92/100 | Created: 2025-12-26
Library: letsplot 4.9.0 | Python 3.13.13
Quality: 89/100 | Updated: 2026-05-09
"""

import os

import numpy as np
import pandas as pd
from lets_plot import *


LetsPlot.setup_html()

# 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"
ACCENT_SOFT = "#D4A574" if THEME == "light" else "#8B7355"
BRAND = "#009E73"

# Data - Daily temperature readings over one year
np.random.seed(42)
dates = pd.date_range(start="2024-01-01", periods=365, freq="D")

# Simulate realistic temperature data with seasonal pattern
day_of_year = np.arange(365)
seasonal_pattern = 15 * np.sin(2 * np.pi * (day_of_year - 80) / 365) # Peak in summer
baseline = 12 # Average temperature
noise = np.random.randn(365) * 3 # Daily variation
seasonal_pattern = 15 * np.sin(2 * np.pi * (day_of_year - 80) / 365)
baseline = 12
noise = np.random.randn(365) * 3
temperature = baseline + seasonal_pattern + noise

df = pd.DataFrame({"date": dates, "temperature": temperature})

# Create plot
# Find peak and trough for visual emphasis
max_idx = df["temperature"].idxmax()
min_idx = df["temperature"].idxmin()
extremes = pd.DataFrame([df.iloc[max_idx], df.iloc[min_idx]])

# Theme-adaptive styling with enhanced refinement
anyplot_theme = theme(
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
panel_background=element_rect(fill=PAGE_BG),
panel_grid_major=element_line(color=INK_SOFT, size=0.25, linetype="solid"),
panel_grid_minor=element_blank(),
axis_title=element_text(size=20, color=INK, face="bold"),
axis_text=element_text(size=16, color=INK_SOFT),
axis_text_x=element_text(angle=45, hjust=1),
plot_title=element_text(size=24, color=INK, face="bold"),
legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT),
legend_text=element_text(size=16, color=INK_SOFT),
legend_title=element_text(size=16, color=INK),
axis_line=element_line(color=INK_SOFT, size=0.4),
)

# Create plot with layered visual hierarchy
plot = (
ggplot(df, aes(x="date", y="temperature"))
+ geom_line(color="#306998", size=1.5, alpha=0.9)
+ labs(x="Date", y="Temperature (°C)", title="line-timeseries · letsplot · pyplots.ai")
+ theme_minimal()
+ theme(
plot_title=element_text(size=24, face="bold"),
axis_title=element_text(size=20),
axis_text=element_text(size=16),
axis_text_x=element_text(angle=45),
panel_grid_major=element_line(color="#CCCCCC", size=0.5),
panel_grid_minor=element_line(color="#EEEEEE", size=0.3),
)
+ ggsize(1600, 900)
+ geom_smooth(method="loess", span=0.15, color=ACCENT_SOFT, size=1.2, alpha=0.5, se=False)
+ geom_line(color=BRAND, size=1.0, alpha=0.8)
+ geom_point(color=BRAND, size=1.5, alpha=0.6)
+ geom_point(data=extremes, color=BRAND, size=3.5, alpha=0.95)
+ labs(x="Date", y="Temperature (°C)", title="line-timeseries · letsplot · anyplot.ai")
+ scale_x_datetime(format="%b %Y")
+ ggsize(1600, 900)
+ anyplot_theme
)

# Save
ggsave(plot, "plot.png", path=".", scale=3)
ggsave(plot, "plot.html", path=".")
ggsave(plot, f"plot-{THEME}.png", path=".", w=4800, h=2700, unit="px", dpi=100)
ggsave(plot, f"plot-{THEME}.html", path=".")
Loading
Loading