{"spec_id":"streamline-basic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nstreamline-basic: Basic Streamline Plot\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 94/100 | Updated: 2026-05-14\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Data - Create a more complex flow field showing vortex and source features\nnp.random.seed(42)\n\n# Grid setup (40x40 for smooth streamlines)\nx = np.linspace(-3, 3, 40)\ny = np.linspace(-3, 3, 40)\nX, Y = np.meshgrid(x, y)\n\n# Create a more interesting flow field combining vortex and source patterns\n# Vortex: u = -y, v = x (circular flow)\n# Add a source/sink at (0, 0): radial outflow\n# Add secondary vortex at (1.5, 0): counterclockwise rotation\nU = -0.8 * Y + 0.3 * X / (X**2 + Y**2 + 0.1)\nV = 0.8 * X + 0.3 * Y / (X**2 + Y**2 + 0.1)\n\n# Secondary vortex contribution\ndx, dy = X - 1.5, Y\nU += -0.4 * dy / ((dx**2 + dy**2 + 0.5) ** 0.5)\nV += 0.4 * dx / ((dx**2 + dy**2 + 0.5) ** 0.5)\n\n# Calculate velocity magnitude for color and linewidth encoding\nspeed = np.sqrt(U**2 + V**2)\nspeed_norm = (speed - speed.min()) / (speed.max() - speed.min() + 1e-6)\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Create streamlines with color based on velocity magnitude\nstrm = ax.streamplot(\n    X,\n    Y,\n    U,\n    V,\n    color=speed,\n    cmap=\"viridis\",\n    linewidth=1.5 + 2.5 * speed_norm,  # Linewidth varies with speed\n    density=1.5,\n    arrowsize=2,\n    arrowstyle=\"->\",\n)\n\n# Colorbar for velocity magnitude\ncbar = fig.colorbar(strm.lines, ax=ax, shrink=0.8, pad=0.02)\ncbar.set_label(\"Velocity Magnitude\", fontsize=20, color=INK)\ncbar.ax.tick_params(labelsize=16, colors=INK_SOFT)\ncbar.outline.set_color(INK_SOFT)\ncbar.outline.set_linewidth(0.5)\n\n# Styling\nax.set_xlabel(\"X Position (m)\", fontsize=20, color=INK)\nax.set_ylabel(\"Y Position (m)\", fontsize=20, color=INK)\nax.set_title(\"streamline-basic · matplotlib · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\nax.set_aspect(\"equal\")\n\n# Grid styling - subtle solid lines\nax.grid(True, alpha=0.10, linestyle=\"-\", linewidth=0.8, color=INK)\n\n# Spine styling\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    ax.spines[s].set_linewidth(0.5)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}