{"spec_id":"line-parametric","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nline-parametric: Parametric Curve Plot\nLibrary: matplotlib 3.11.0 | Python 3.13.14\nQuality: 90/100 | Updated: 2026-06-20\n\"\"\"\n\nimport os as _os\nimport sys as _sys\n\n\n# Prevent this file (matplotlib.py) from shadowing the installed matplotlib package\n_here = _os.path.dirname(_os.path.abspath(__file__))\n_sys.path = [p for p in _sys.path if _os.path.abspath(p) != _here]\ndel _sys, _here\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib.collections import LineCollection\nfrom matplotlib.colors import LinearSegmentedColormap\n\n\n# Theme-adaptive chrome 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\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\n# Imprint sequential colormap — used for continuous parametric parameter t\nimprint_seq = LinearSegmentedColormap.from_list(\"imprint_seq\", [\"#009E73\", \"#4467A3\"])\n\n# Semantic marker colors: green=start (go), red=end (stop) — Imprint positions 1 and 5\nCOLOR_START = \"#009E73\"  # Imprint position 1 — brand green\nCOLOR_END = \"#AE3030\"  # Imprint position 5 — matte red\n\n# --- Data ---\nt_lissajous = np.linspace(0, 2 * np.pi, 1000)\nx_lissajous = np.sin(3 * t_lissajous)\ny_lissajous = np.sin(2 * t_lissajous)\n\nt_spiral = np.linspace(0, 4 * np.pi, 1000)\nx_spiral = t_spiral * np.cos(t_spiral)\ny_spiral = t_spiral * np.sin(t_spiral)\n\n# --- Canvas: 3200 × 1800 px (landscape 16:9, hard rule — no deviation) ---\nfig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nfor ax in (ax1, ax2):\n    ax.set_facecolor(PAGE_BG)\n\n# --- Lissajous panel ---\npoints_l = np.array([x_lissajous, y_lissajous]).T.reshape(-1, 1, 2)\nsegments_l = np.concatenate([points_l[:-1], points_l[1:]], axis=1)\nlc1 = LineCollection(segments_l, cmap=imprint_seq, linewidth=2.5, capstyle=\"round\")\nlc1.set_array(t_lissajous[:-1])\nax1.add_collection(lc1)\nax1.set_xlim(x_lissajous.min() - 0.15, x_lissajous.max() + 0.15)\nax1.set_ylim(y_lissajous.min() - 0.15, y_lissajous.max() + 0.15)\nax1.plot(\n    x_lissajous[0],\n    y_lissajous[0],\n    \"o\",\n    color=COLOR_START,\n    markersize=7,\n    zorder=5,\n    label=\"Start (t = 0)\",\n    markeredgecolor=PAGE_BG,\n    markeredgewidth=1.0,\n)\nax1.plot(\n    x_lissajous[-1],\n    y_lissajous[-1],\n    \"s\",\n    color=COLOR_END,\n    markersize=7,\n    zorder=5,\n    label=\"End (t = 2π)\",\n    markeredgecolor=PAGE_BG,\n    markeredgewidth=1.0,\n)\ncb1 = fig.colorbar(lc1, ax=ax1, pad=0.03, aspect=30, shrink=0.85)\ncb1.set_label(\"Parameter t (rad)\", fontsize=8, labelpad=6, color=INK_SOFT)\ncb1.ax.tick_params(labelsize=7, colors=INK_SOFT)\ncb1.outline.set_visible(False)\nax1.annotate(\n    \"Self-intersection\\nat origin (3:2 ratio)\",\n    xy=(0, 0),\n    xytext=(0.45, -0.72),\n    fontsize=7,\n    color=INK_MUTED,\n    fontstyle=\"italic\",\n    arrowprops={\"arrowstyle\": \"->\", \"color\": INK_MUTED, \"lw\": 0.8},\n    ha=\"center\",\n)\n\n# --- Archimedean Spiral panel ---\npoints_s = np.array([x_spiral, y_spiral]).T.reshape(-1, 1, 2)\nsegments_s = np.concatenate([points_s[:-1], points_s[1:]], axis=1)\nlc2 = LineCollection(segments_s, cmap=imprint_seq, linewidth=2.5, capstyle=\"round\")\nlc2.set_array(t_spiral[:-1])\nax2.add_collection(lc2)\nmargin = t_spiral.max() * 0.1\nax2.set_xlim(x_spiral.min() - margin, x_spiral.max() + margin)\nax2.set_ylim(y_spiral.min() - margin, y_spiral.max() + margin)\nax2.plot(\n    x_spiral[0],\n    y_spiral[0],\n    \"o\",\n    color=COLOR_START,\n    markersize=7,\n    zorder=5,\n    label=\"Start (t = 0)\",\n    markeredgecolor=PAGE_BG,\n    markeredgewidth=1.0,\n)\nax2.plot(\n    x_spiral[-1],\n    y_spiral[-1],\n    \"s\",\n    color=COLOR_END,\n    markersize=7,\n    zorder=5,\n    label=\"End (t = 4π)\",\n    markeredgecolor=PAGE_BG,\n    markeredgewidth=1.0,\n)\ncb2 = fig.colorbar(lc2, ax=ax2, pad=0.03, aspect=30, shrink=0.85)\ncb2.set_label(\"Parameter t (rad)\", fontsize=8, labelpad=6, color=INK_SOFT)\ncb2.ax.tick_params(labelsize=7, colors=INK_SOFT)\ncb2.outline.set_visible(False)\nax2.annotate(\n    \"Radius grows\\nlinearly with t\",\n    xy=(x_spiral[750], y_spiral[750]),\n    xytext=(6, 8),\n    fontsize=7,\n    color=INK_MUTED,\n    fontstyle=\"italic\",\n    arrowprops={\"arrowstyle\": \"->\", \"color\": INK_MUTED, \"lw\": 0.8},\n    ha=\"center\",\n)\n\n# --- Per-panel styling: equal aspect, spines, labels, legend, grid ---\npanel_info = [\n    (ax1, \"Lissajous Figure\", \"x(t) = sin(3t)\", \"y(t) = sin(2t)\"),\n    (ax2, \"Archimedean Spiral\", \"x(t) = t · cos(t)\", \"y(t) = t · sin(t)\"),\n]\nfor ax, title_text, xlabel, ylabel in panel_info:\n    ax.set_aspect(\"equal\")\n    ax.set_xlabel(xlabel, fontsize=10, color=INK)\n    ax.set_ylabel(ylabel, fontsize=10, color=INK)\n    ax.set_title(title_text, fontsize=12, fontweight=\"medium\", pad=8, color=INK)\n    ax.tick_params(axis=\"both\", labelsize=8, colors=INK_SOFT)\n    for spine in ax.spines.values():\n        spine.set_visible(False)\n    leg = ax.legend(fontsize=8, loc=\"lower right\", frameon=True, fancybox=False, framealpha=0.9)\n    if leg:\n        leg.get_frame().set_facecolor(ELEVATED_BG)\n        leg.get_frame().set_edgecolor(INK_SOFT)\n        plt.setp(leg.get_texts(), color=INK_SOFT)\n    ax.grid(True, alpha=0.15, linewidth=0.6, color=INK)\n\n# --- Figure title ---\ntitle = \"line-parametric · python · matplotlib · anyplot.ai\"\nfig.suptitle(title, fontsize=12, fontweight=\"medium\", y=0.98, color=INK)\n\nplt.tight_layout(rect=[0, 0, 1, 0.94])\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}