{"spec_id":"line-timeseries","library":"altair","language":"python","code":"\"\"\" anyplot.ai\nline-timeseries: Time Series Line Plot\nLibrary: altair 6.1.0 | Python 3.13.13\nQuality: 92/100 | Updated: 2026-05-09\n\"\"\"\n\nimport os\nimport sys\n\n\n# Remove the current directory from sys.path to avoid importing altair.py\nsys.path = [p for p in sys.path if p != \"\" and not p.endswith(\"python\")]\n\nimport altair as alt\nimport numpy as np\nimport pandas as pd\n\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\"\nBRAND = \"#009E73\"  # Okabe-Ito position 1\n\n# Data - Daily stock prices over one year\nnp.random.seed(42)\n\n# Generate 252 trading days (one year of stock market data)\ndates = pd.date_range(start=\"2024-01-02\", periods=252, freq=\"B\")\n\n# Simulate stock price with trend and volatility\nprice = 100.0\nprices = [price]\nfor _ in range(251):\n    # Random walk with slight upward drift\n    change = np.random.randn() * 2 + 0.05\n    price = max(price + change, 50)  # Floor at 50\n    prices.append(price)\n\ndf = pd.DataFrame({\"date\": dates, \"price\": prices})\n\n# Create time series line chart\nchart = (\n    alt.Chart(df)\n    .mark_line(strokeWidth=3, color=BRAND, point=True, size=150)\n    .encode(\n        x=alt.X(\n            \"date:T\",\n            title=\"Date\",\n            axis=alt.Axis(\n                format=\"%b %Y\",\n                labelFontSize=18,\n                titleFontSize=22,\n                labelAngle=-45,\n                tickCount=12,\n                labelColor=INK_SOFT,\n                titleColor=INK,\n                domainColor=INK_SOFT,\n                gridColor=INK,\n                gridOpacity=0.10,\n            ),\n        ),\n        y=alt.Y(\n            \"price:Q\",\n            title=\"Stock Price ($)\",\n            scale=alt.Scale(zero=False),\n            axis=alt.Axis(\n                labelFontSize=18,\n                titleFontSize=22,\n                labelColor=INK_SOFT,\n                titleColor=INK,\n                domainColor=INK_SOFT,\n                gridColor=INK,\n                gridOpacity=0.10,\n            ),\n        ),\n        tooltip=[\n            alt.Tooltip(\"date:T\", title=\"Date\", format=\"%B %d, %Y\"),\n            alt.Tooltip(\"price:Q\", title=\"Price\", format=\"$.2f\"),\n        ],\n    )\n    .properties(\n        width=1600,\n        height=900,\n        background=PAGE_BG,\n        title=alt.Title(\"line-timeseries · altair · anyplot.ai\", fontSize=28, anchor=\"middle\", color=INK),\n    )\n    .configure_view(fill=PAGE_BG, stroke=INK_SOFT, strokeWidth=1)\n    .configure_title(color=INK, fontSize=28)\n    .configure_legend(fillColor=ELEVATED_BG, strokeColor=INK_SOFT, labelColor=INK_SOFT, titleColor=INK)\n    .interactive()\n)\n\n# Save outputs\nscript_dir = os.path.dirname(os.path.abspath(__file__))\nchart.save(os.path.join(script_dir, f\"plot-{THEME}.png\"), scale_factor=3.0)\nchart.save(os.path.join(script_dir, f\"plot-{THEME}.html\"))\n"}