{"spec_id":"line-styled","library":"letsplot","language":"python","code":"# ruff: noqa: F405\n\"\"\"anyplot.ai\nline-styled: Styled Line Plot\nLibrary: lets-plot | Python 3.13\nQuality: pending | Created: 2025-12-30\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\"\n\n# Okabe-Ito palette\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\"]\n\n# Data - Daily rainfall across different cities over a month\nnp.random.seed(42)\ndays = np.arange(1, 31)\n\n# Realistic rainfall patterns for different cities (mm/day)\nparis = 15 + np.cumsum(np.random.randn(30) * 2) / 5\nathens = 5 + np.cumsum(np.random.randn(30) * 1) / 5\nseattle = 20 + np.cumsum(np.random.randn(30) * 2.5) / 5\ndelhi = 8 + np.cumsum(np.random.randn(30) * 1.5) / 5\n\n# Create long-format DataFrame for lets-plot\ndf = pd.DataFrame(\n    {\n        \"Day\": np.tile(days, 4),\n        \"Rainfall\": np.concatenate([paris, athens, seattle, delhi]),\n        \"City\": np.repeat([\"Paris\", \"Athens\", \"Seattle\", \"Delhi\"], 30),\n    }\n)\n\n# Custom theme for anyplot\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, size=0.2),\n    panel_grid_minor=element_blank(),\n    axis_title=element_text(size=20, color=INK),\n    axis_text=element_text(size=16, color=INK_SOFT),\n    axis_line=element_line(color=INK_SOFT, size=0.5),\n    plot_title=element_text(size=24, color=INK),\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    legend_position=\"right\",\n)\n\n# Create plot with different line styles\nplot = (\n    ggplot(df, aes(x=\"Day\", y=\"Rainfall\", color=\"City\", linetype=\"City\"))\n    + geom_line(size=2)\n    + geom_point(size=3.5, alpha=0.7)\n    + scale_color_manual(values=IMPRINT)\n    + scale_linetype_manual(values=[\"solid\", \"dashed\", \"dotted\", \"longdash\"])\n    + labs(\n        x=\"Day of Month\", y=\"Rainfall (mm)\", title=\"line-styled · letsplot · anyplot.ai\", color=\"City\", linetype=\"City\"\n    )\n    + anyplot_theme\n    + ggsize(1600, 900)\n)\n\n# Save as PNG (scale 3x = 4800 × 2700 px)\nggsave(plot, f\"plot-{THEME}.png\", path=\".\", scale=3)\n\n# Save as HTML for interactive viewing\nggsave(plot, f\"plot-{THEME}.html\", path=\".\")\n"}