{"spec_id":"line-stepwise","library":"altair","language":"python","code":"\"\"\" anyplot.ai\nline-stepwise: Step Line Plot\nLibrary: altair 6.1.0 | Python 3.13.13\nQuality: 91/100 | Updated: 2026-05-13\n\"\"\"\n\nimport os\nimport sys\n\n\n# Workaround for import conflict: remove script directory from path\nscript_dir = os.path.dirname(os.path.abspath(__file__))\nif script_dir in sys.path:\n    sys.path.remove(script_dir)\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\"\n\n# Data - Discrete price changes showing step behavior (both increases and decreases)\nnp.random.seed(42)\ndays = np.arange(0, 25)\n# Price values that step discretely, with varied pattern\nbase_price = 100\nprice_changes = [0, 0, 5, 5, 0, -3, -3, -3, 8, 8, 8, 2, 2, -2, -2, -2, 6, 6, 3, 3, 3, 1, 1, 1, 0]\nprices = base_price + np.cumsum(price_changes)\n\ndf = pd.DataFrame({\"Day\": days, \"Price ($)\": prices})\n\n# Create step line chart using interpolate='step-after'\nchart = (\n    alt.Chart(df)\n    .mark_line(interpolate=\"step-after\", strokeWidth=4, color=BRAND)\n    .encode(\n        x=alt.X(\"Day:Q\", title=\"Day\", axis=alt.Axis(labelFontSize=18, titleFontSize=22)),\n        y=alt.Y(\n            \"Price ($):Q\",\n            title=\"Price ($)\",\n            scale=alt.Scale(zero=False),\n            axis=alt.Axis(labelFontSize=18, titleFontSize=22),\n        ),\n        tooltip=[\"Day\", \"Price ($)\"],\n    )\n    .properties(\n        width=1600,\n        height=900,\n        background=PAGE_BG,\n        title=alt.Title(\"line-stepwise · altair · anyplot.ai\", fontSize=28, anchor=\"middle\"),\n    )\n    .configure_axis(\n        domainColor=INK_SOFT,\n        tickColor=INK_SOFT,\n        gridColor=INK,\n        gridOpacity=0.15,\n        labelColor=INK_SOFT,\n        titleColor=INK,\n        grid=True,\n        gridDash=[4, 4],\n    )\n    .configure_view(strokeWidth=0, fill=PAGE_BG)\n    .configure_title(color=INK)\n)\n\n# Save as PNG (1600 × 900 * 3 = 4800 × 2700 px)\nchart.save(f\"plot-{THEME}.png\", scale_factor=3.0)\n\n# Save as HTML for interactivity\nchart.save(f\"plot-{THEME}.html\")\n"}