{"spec_id":"line-timeseries","library":"letsplot","language":"python","code":"\"\"\" anyplot.ai\nline-timeseries: Time Series Line Plot\nLibrary: letsplot 4.9.0 | Python 3.13.13\nQuality: 89/100 | Updated: 2026-05-09\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom lets_plot import *\n\n\nLetsPlot.setup_html()\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nACCENT_SOFT = \"#D4A574\" if THEME == \"light\" else \"#8B7355\"\nBRAND = \"#009E73\"\n\n# Data - Daily temperature readings over one year\nnp.random.seed(42)\ndates = pd.date_range(start=\"2024-01-01\", periods=365, freq=\"D\")\n\n# Simulate realistic temperature data with seasonal pattern\nday_of_year = np.arange(365)\nseasonal_pattern = 15 * np.sin(2 * np.pi * (day_of_year - 80) / 365)\nbaseline = 12\nnoise = np.random.randn(365) * 3\ntemperature = baseline + seasonal_pattern + noise\n\ndf = pd.DataFrame({\"date\": dates, \"temperature\": temperature})\n\n# Find peak and trough for visual emphasis\nmax_idx = df[\"temperature\"].idxmax()\nmin_idx = df[\"temperature\"].idxmin()\nextremes = pd.DataFrame([df.iloc[max_idx], df.iloc[min_idx]])\n\n# Theme-adaptive styling with enhanced refinement\nanyplot_theme = theme(\n    plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n    panel_background=element_rect(fill=PAGE_BG),\n    panel_grid_major=element_line(color=INK_SOFT, size=0.25, linetype=\"solid\"),\n    panel_grid_minor=element_blank(),\n    axis_title=element_text(size=20, color=INK, face=\"bold\"),\n    axis_text=element_text(size=16, color=INK_SOFT),\n    axis_text_x=element_text(angle=45, hjust=1),\n    plot_title=element_text(size=24, color=INK, face=\"bold\"),\n    legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT),\n    legend_text=element_text(size=16, color=INK_SOFT),\n    legend_title=element_text(size=16, color=INK),\n    axis_line=element_line(color=INK_SOFT, size=0.4),\n)\n\n# Create plot with layered visual hierarchy\nplot = (\n    ggplot(df, aes(x=\"date\", y=\"temperature\"))\n    + geom_smooth(method=\"loess\", span=0.15, color=ACCENT_SOFT, size=1.2, alpha=0.5, se=False)\n    + geom_line(color=BRAND, size=1.0, alpha=0.8)\n    + geom_point(color=BRAND, size=1.5, alpha=0.6)\n    + geom_point(data=extremes, color=BRAND, size=3.5, alpha=0.95)\n    + labs(x=\"Date\", y=\"Temperature (°C)\", title=\"line-timeseries · letsplot · anyplot.ai\")\n    + scale_x_datetime(format=\"%b %Y\")\n    + ggsize(1600, 900)\n    + anyplot_theme\n)\n\n# Save\nggsave(plot, f\"plot-{THEME}.png\", path=\".\", w=4800, h=2700, unit=\"px\", dpi=100)\nggsave(plot, f\"plot-{THEME}.html\", path=\".\")\n"}