{"spec_id":"quiver-basic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nquiver-basic: Basic Quiver Plot\nLibrary: matplotlib 3.11.1 | Python 3.13.14\nQuality: 90/100 | Updated: 2026-07-24\n\"\"\"\n\nimport os\nimport sys\n\n\n# Prevent this file (matplotlib.py) from shadowing the real matplotlib package\nsys.path = [p for p in sys.path if os.path.abspath(p or \".\") != os.path.dirname(os.path.abspath(__file__))]\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib.colors import LinearSegmentedColormap\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# Imprint sequential colormap (brand green -> blue) for single-polarity speed\nimprint_seq = LinearSegmentedColormap.from_list(\"imprint_seq\", [\"#009E73\", \"#4467A3\"])\n\n# Data - Rankine combined vortex, a textbook model for an ocean mesoscale eddy:\n# solid-body rotation inside the core radius, irrotational 1/r decay outside.\n# This keeps arrows near the center visible (unlike a pure u=-y, v=x field,\n# whose magnitude vanishes to zero exactly at the origin) while still tapering\n# gently at the domain edges.\ngrid_size = 17\nkm = np.linspace(-60, 60, grid_size)\nX, Y = np.meshgrid(km, km)\nR = np.sqrt(X**2 + Y**2)\ntheta = np.arctan2(Y, X)\n\ncore_radius = 20.0  # km, radius of peak tangential speed\nv_max = 1.2  # m/s, peak tangential current speed at the core edge\nR_safe = np.where(R == 0, 1e-6, R)\nspeed = np.where(R <= core_radius, v_max * R / core_radius, v_max * core_radius / R_safe)\n\nU = -speed * np.sin(theta)\nV = speed * np.cos(theta)\n\n# Plot\nfig, ax = plt.subplots(figsize=(6, 6), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\nquiver = ax.quiver(\n    X, Y, U, V, speed, cmap=imprint_seq, scale=14, width=0.007, headwidth=4, headlength=5, headaxislength=4.5\n)\n\n# Reference arrow — a distinctly matplotlib feature that anchors the eye to\n# an exact speed, since color alone only conveys relative magnitude.\nax.quiverkey(\n    quiver,\n    X=0.86,\n    Y=0.93,\n    U=v_max,\n    label=f\"{v_max:.1f} m/s\",\n    labelpos=\"S\",\n    coordinates=\"axes\",\n    color=INK,\n    labelcolor=INK,\n    fontproperties={\"size\": 8},\n)\n\n# Colorbar\ncbar = plt.colorbar(quiver, ax=ax, shrink=0.8, pad=0.03)\ncbar.set_label(\"Current Speed (m/s)\", fontsize=10, color=INK)\ncbar.ax.tick_params(labelsize=8, colors=INK_SOFT)\ncbar.ax.set_facecolor(PAGE_BG)\ncbar.outline.set_edgecolor(INK_SOFT)\n\n# Style\ntitle = \"quiver-basic · python · matplotlib · anyplot.ai\"\nn = len(title)\nratio = 67 / n if n > 67 else 1.0\ntitle_fontsize = max(8, round(12 * ratio))\n\nax.set_xlabel(\"Distance East of Eddy Center (km)\", fontsize=10, color=INK)\nax.set_ylabel(\"Distance North of Eddy Center (km)\", 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)\nax.set_aspect(\"equal\")\n\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\nax.grid(True, alpha=0.15, linewidth=0.8, color=INK)\n\nfig.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)  # do NOT add bbox_inches='tight'\n"}