{"spec_id":"phase-diagram-pt","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nphase-diagram-pt: Thermodynamic Phase Diagram (Pressure-Temperature)\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 92/100 | Updated: 2026-06-08\n\"\"\"\n\nimport os\n\nimport matplotlib.patheffects as pe\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\"\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 palette — positions used by semantic role\n# 1=green (boundary curves + liquid region), 3=blue (solid/ice), 4=ochre (supercritical),\n# 5=red (key point markers), 6=cyan (gas/atmosphere)\nIMPRINT_PALETTE = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\"]\n\n# Data — Water phase diagram (real physical constants)\n# Triple point: 273.16 K, 611.73 Pa\n# Critical point: 647.1 K, 22.064 MPa\ntriple_T, triple_P = 273.16, 611.73\ncritical_T, critical_P = 647.1, 22.064e6\n\nR = 8.314  # J/(mol·K)\n\n# Sublimation curve: solid-gas boundary (Clausius-Clapeyron)\nT_solid_gas = np.linspace(200, triple_T, 80)\nL_sub = 51059  # J/mol sublimation enthalpy for water\nP_solid_gas = triple_P * np.exp((L_sub / R) * (1 / triple_T - 1 / T_solid_gas))\n\n# Vaporization curve: liquid-gas boundary (triple point → critical point)\nT_liquid_gas = np.linspace(triple_T, critical_T, 100)\nL_vap = 40670  # J/mol vaporization enthalpy for water\nP_liquid_gas = triple_P * np.exp((L_vap / R) * (1 / triple_T - 1 / T_liquid_gas))\n\n# Melting curve: solid-liquid boundary — water has anomalous negative slope\nT_solid_liquid = np.linspace(triple_T, 240, 100)\nP_solid_liquid = triple_P + (T_solid_liquid - triple_T) * (-1.4e7)\n\n# Plot — landscape canvas: 3200 × 1800 px\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\nax.set_yscale(\"log\")\nx_min, x_max = 180, 800\ny_min, y_max = 10, 5e8\nax.set_xlim(x_min, x_max)\nax.set_ylim(y_min, y_max)\n\n# Phase region fills — Imprint palette at low alpha, semantic color mapping\n# gas → cyan (atmosphere), liquid → green (water/life), solid → blue (ice), supercritical → ochre (heat)\ngas_T = np.concatenate([T_solid_gas, T_liquid_gas])\ngas_P = np.concatenate([P_solid_gas, P_liquid_gas])\nax.fill_between(gas_T, y_min, gas_P, color=IMPRINT_PALETTE[5], alpha=0.20, zorder=1)\n\nax.fill_between(T_liquid_gas, P_liquid_gas, y_max, color=IMPRINT_PALETTE[0], alpha=0.20, zorder=1)\n\nsolid_T = np.concatenate([[x_min], T_solid_gas, T_solid_liquid[::-1], [T_solid_liquid[-1]], [x_min]])\nsolid_P = np.concatenate([[P_solid_gas[0]], P_solid_gas, P_solid_liquid[::-1], [y_max], [y_max]])\nax.fill(solid_T, solid_P, color=IMPRINT_PALETTE[2], alpha=0.20, zorder=1)\n\nax.fill_between([critical_T, x_max], critical_P, y_max, color=IMPRINT_PALETTE[3], alpha=0.20, zorder=1)\n\n# Dashed reference lines at the critical point\nax.axhline(critical_P, color=INK_MUTED, linewidth=0.8, linestyle=(0, (5, 5)), alpha=0.4, zorder=2)\nax.axvline(critical_T, color=INK_MUTED, linewidth=0.8, linestyle=(0, (5, 5)), alpha=0.4, zorder=2)\n\n# Phase boundary curves — all Imprint brand green (single boundary type)\ntext_outline = [pe.withStroke(linewidth=3, foreground=PAGE_BG)]\ncurve_color = IMPRINT_PALETTE[0]  # #009E73\nax.plot(T_solid_gas, P_solid_gas, color=curve_color, linewidth=2.5, zorder=3)\nax.plot(T_liquid_gas, P_liquid_gas, color=curve_color, linewidth=2.5, zorder=3)\nax.plot(T_solid_liquid, P_solid_liquid, color=curve_color, linewidth=2.5, zorder=3)\n\n# Special point markers — matte red (semantic: significant physical states)\npt_color = IMPRINT_PALETTE[4]  # #AE3030\nax.scatter(triple_T, triple_P, s=120, color=pt_color, edgecolors=PAGE_BG, linewidth=1.5, zorder=5)\nax.scatter(critical_T, critical_P, s=120, color=pt_color, edgecolors=PAGE_BG, linewidth=1.5, zorder=5)\n\n# Annotations for key points\nax.annotate(\n    \"Triple Point\\n(273.16 K, 611.73 Pa)\",\n    xy=(triple_T, triple_P),\n    xytext=(38, -30),\n    textcoords=\"offset points\",\n    fontsize=7.5,\n    color=INK,\n    arrowprops={\"arrowstyle\": \"->\", \"color\": INK_MUTED, \"lw\": 1.0},\n    bbox={\"facecolor\": ELEVATED_BG, \"edgecolor\": INK_SOFT, \"alpha\": 0.85, \"pad\": 2, \"boxstyle\": \"round,pad=0.3\"},\n    zorder=6,\n)\nax.annotate(\n    \"Critical Point\\n(647.1 K, 22.06 MPa)\",\n    xy=(critical_T, critical_P),\n    xytext=(-65, 28),\n    textcoords=\"offset points\",\n    fontsize=7.5,\n    color=INK,\n    arrowprops={\"arrowstyle\": \"->\", \"color\": INK_MUTED, \"lw\": 1.0},\n    bbox={\"facecolor\": ELEVATED_BG, \"edgecolor\": INK_SOFT, \"alpha\": 0.85, \"pad\": 2, \"boxstyle\": \"round,pad=0.3\"},\n    zorder=6,\n)\n\n# Phase region labels with path effects for readability over fills\nax.text(\n    215,\n    5e6,\n    \"SOLID\",\n    fontsize=9,\n    fontweight=\"bold\",\n    color=IMPRINT_PALETTE[2],\n    alpha=0.9,\n    ha=\"center\",\n    path_effects=text_outline,\n    zorder=4,\n)\nax.text(\n    420,\n    5e6,\n    \"LIQUID\",\n    fontsize=9,\n    fontweight=\"bold\",\n    color=IMPRINT_PALETTE[0],\n    alpha=0.9,\n    ha=\"center\",\n    path_effects=text_outline,\n    zorder=4,\n)\nax.text(\n    550,\n    50,\n    \"GAS\",\n    fontsize=9,\n    fontweight=\"bold\",\n    color=IMPRINT_PALETTE[5],\n    alpha=0.9,\n    ha=\"center\",\n    path_effects=text_outline,\n    zorder=4,\n)\nax.text(\n    720,\n    8e7,\n    \"SUPERCRITICAL\\nFLUID\",\n    fontsize=8,\n    fontweight=\"bold\",\n    color=IMPRINT_PALETTE[3],\n    alpha=0.9,\n    ha=\"center\",\n    path_effects=text_outline,\n    zorder=4,\n)\n\n# Style\ntitle = \"phase-diagram-pt · python · matplotlib · anyplot.ai\"\ntitle_fontsize = max(8, round(12 * 67 / len(title))) if len(title) > 67 else 12\n\nax.set_xlabel(\"Temperature (K)\", fontsize=10, color=INK)\nax.set_ylabel(\"Pressure (Pa)\", 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.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nfor s in (\"left\", \"bottom\"):\n    ax.spines[s].set_color(INK_SOFT)\nax.yaxis.grid(True, alpha=0.15, linewidth=0.8, color=INK)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}