{"spec_id":"line-multi","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nline-multi: Multi-Line Comparison Plot\nLibrary: matplotlib 3.11.1 | Python 3.13.14\nQuality: 91/100 | Updated: 2026-08-05\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib import patheffects\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\"\n\n# Imprint palette (positions 1-3, canonical order)\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\"]\n\n# Data: Monthly sales (in thousands) for 3 product lines over 12 months\nnp.random.seed(42)\nmonths = np.arange(1, 13)\nmonth_labels = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"]\n\n# Product A: Steady growth with seasonal bump in Q4\nproduct_a = 50 + np.arange(12) * 3 + np.array([0, 0, 0, 0, 0, 5, 5, 0, 10, 15, 20, 25])\nproduct_a = product_a + np.random.randn(12) * 3\n\n# Product B: Strong start, mid-year dip, recovery\nproduct_b = 80 + np.array([0, -5, -10, -15, -20, -25, -20, -15, -10, -5, 0, 5])\nproduct_b = product_b + np.random.randn(12) * 4\n\n# Product C: New product launch, exponential growth\nproduct_c = 20 + np.exp(np.arange(12) * 0.15) * 10\nproduct_c = product_c + np.random.randn(12) * 2\n\n# Plot\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Soft halo (matplotlib patheffects) keeps lines legible where they cross the grid\nhalo = [patheffects.withStroke(linewidth=4, foreground=PAGE_BG)]\n\n# Plot each series with distinct colors, line styles, and markers\nax.plot(\n    months,\n    product_a,\n    color=IMPRINT[0],\n    linewidth=3,\n    marker=\"o\",\n    markersize=9,\n    label=\"Product A (Electronics)\",\n    linestyle=\"-\",\n    path_effects=halo,\n)\nax.plot(\n    months,\n    product_b,\n    color=IMPRINT[1],\n    linewidth=3,\n    marker=\"s\",\n    markersize=9,\n    label=\"Product B (Appliances)\",\n    linestyle=\"--\",\n    path_effects=halo,\n)\nax.plot(\n    months,\n    product_c,\n    color=IMPRINT[2],\n    linewidth=3,\n    marker=\"^\",\n    markersize=9,\n    label=\"Product C (Software)\",\n    linestyle=\"-.\",\n    path_effects=halo,\n)\n\n# Highlight peak value with annotation\nmax_a_idx = np.argmax(product_a)\nax.annotate(\n    f\"${product_a[max_a_idx]:.0f}K\",\n    xy=(months[max_a_idx], product_a[max_a_idx]),\n    xytext=(10, 15),\n    textcoords=\"offset points\",\n    fontsize=9,\n    color=INK_SOFT,\n    bbox={\"boxstyle\": \"round,pad=0.4\", \"facecolor\": ELEVATED_BG, \"edgecolor\": INK_SOFT, \"alpha\": 0.9},\n    arrowprops={\"arrowstyle\": \"->\", \"connectionstyle\": \"arc3,rad=0\", \"color\": INK_SOFT, \"lw\": 1.2},\n)\n\n# Style\ntitle = \"line-multi · python · matplotlib · anyplot.ai\"\nn = len(title)\ntitle_fontsize = max(8, round(12 * 67 / n)) if n > 67 else 12\nax.set_xlabel(\"Month\", fontsize=10, color=INK)\nax.set_ylabel(\"Sales ($ thousands)\", fontsize=10, color=INK)\nax.set_title(title, fontsize=title_fontsize, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=8, colors=INK_SOFT, labelcolor=INK_SOFT, length=0)\n\n# Set x-axis ticks to show month labels\nax.set_xticks(months)\nax.set_xticklabels(month_labels)\n\n# Grid\nax.yaxis.grid(True, alpha=0.12, linewidth=0.8, color=INK_SOFT)\n\n# Spines\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nfor s in (\"left\", \"bottom\"):\n    ax.spines[s].set_color(INK_SOFT)\n\n# Legend\nleg = ax.legend(fontsize=8, loc=\"upper left\")\nif leg:\n    leg.get_frame().set_facecolor(ELEVATED_BG)\n    leg.get_frame().set_edgecolor(INK_SOFT)\n    leg.get_frame().set_linewidth(0.8)\n    plt.setp(leg.get_texts(), color=INK_SOFT)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}