{"spec_id":"phase-diagram-pt","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nphase-diagram-pt: Thermodynamic Phase Diagram (Pressure-Temperature)\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-06-08\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\n\n\n# Theme tokens — Imprint palette, theme-adaptive chrome\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 1–3 for three phase boundaries\nIMPRINT_PALETTE = [\"#009E73\", \"#C475FD\", \"#4467A3\"]\n\nsns.set_theme(\n    context=\"notebook\",\n    style=\"ticks\",\n    rc={\n        \"figure.facecolor\": PAGE_BG,\n        \"axes.facecolor\": PAGE_BG,\n        \"axes.edgecolor\": INK_SOFT,\n        \"axes.labelcolor\": INK,\n        \"text.color\": INK,\n        \"xtick.color\": INK_SOFT,\n        \"ytick.color\": INK_SOFT,\n        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\n# Data — water phase diagram, Clausius-Clapeyron approximation\n# Triple point: 273.16 K / 611.73 Pa; critical point: 647.1 K / 22.064 MPa\ntriple_T, triple_P = 273.16, 611.73\ncritical_T, critical_P = 647.1, 22_064_000.0\nR = 8.314\n\nT_sub = np.linspace(200, triple_T, 100)\nP_sub = triple_P * np.exp((51059.0 / R) * (1 / triple_T - 1 / T_sub))\n\nT_vap = np.linspace(triple_T, critical_T, 100)\nP_vap = triple_P * np.exp((40660.0 / R) * (1 / triple_T - 1 / T_vap))\n\n# Water melting curve — anomalous negative slope (increasing pressure lowers melting point)\nP_melt = np.logspace(np.log10(triple_P), np.log10(critical_P * 5), 100)\nT_melt = triple_T + (-7.4e-8) * (P_melt - triple_P)\n\ndf = pd.concat(\n    [\n        pd.DataFrame({\"Temperature (K)\": T_sub, \"Pressure (Pa)\": P_sub, \"Boundary\": \"Sublimation\"}),\n        pd.DataFrame({\"Temperature (K)\": T_vap, \"Pressure (Pa)\": P_vap, \"Boundary\": \"Vaporization\"}),\n        pd.DataFrame({\"Temperature (K)\": T_melt, \"Pressure (Pa)\": P_melt, \"Boundary\": \"Melting\"}),\n    ],\n    ignore_index=True,\n)\n\n# Plot\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\nsns.lineplot(\n    data=df,\n    x=\"Temperature (K)\",\n    y=\"Pressure (Pa)\",\n    hue=\"Boundary\",\n    style=\"Boundary\",\n    palette=IMPRINT_PALETTE,\n    linewidth=2.5,\n    ax=ax,\n)\n\n# Subtle phase-region fills to visually separate regions\nT_solid_ext = np.concatenate([[190], T_sub])\nP_solid_ext = np.concatenate([[P_sub[0]], P_sub])\nax.fill_between(T_solid_ext, P_solid_ext, 1e9, color=IMPRINT_PALETTE[0], alpha=0.06, zorder=0)\ngas_T = np.concatenate([T_sub, T_vap[1:]])\ngas_P = np.concatenate([P_sub, P_vap[1:]])\nax.fill_between(gas_T, 1e1, gas_P, color=IMPRINT_PALETTE[1], alpha=0.06, zorder=0)\nax.fill_between(T_vap, P_vap, critical_P, color=IMPRINT_PALETTE[2], alpha=0.06, zorder=0)\nax.fill_between([critical_T, 760], critical_P, 1e9, color=INK_MUTED, alpha=0.05, zorder=0)\n\n# Mark triple point (ochre) and critical point (matte red) — seaborn scatter for LM-02\nspecial_df = pd.DataFrame(\n    {\n        \"Temperature (K)\": [triple_T, critical_T],\n        \"Pressure (Pa)\": [triple_P, critical_P],\n        \"Marker\": [\"Triple Point\", \"Critical Point\"],\n    }\n)\nsns.scatterplot(\n    data=special_df,\n    x=\"Temperature (K)\",\n    y=\"Pressure (Pa)\",\n    hue=\"Marker\",\n    style=\"Marker\",\n    palette={\"Triple Point\": \"#BD8233\", \"Critical Point\": \"#AE3030\"},\n    markers={\"Triple Point\": \"o\", \"Critical Point\": \"D\"},\n    s=80,\n    zorder=5,\n    ax=ax,\n    legend=False,\n    edgecolors=PAGE_BG,\n    linewidths=1.2,\n)\n\nax.annotate(\n    \"Triple Point\\n(273 K, 612 Pa)\",\n    xy=(triple_T, triple_P),\n    xytext=(triple_T + 40, triple_P * 0.06),\n    fontsize=8,\n    color=\"#BD8233\",\n    arrowprops={\"arrowstyle\": \"->\", \"color\": \"#BD8233\", \"lw\": 1.2},\n    va=\"center\",\n)\nax.annotate(\n    \"Critical Point\\n(647 K, 22.1 MPa)\",\n    xy=(critical_T, critical_P),\n    xytext=(critical_T - 120, critical_P * 7),\n    fontsize=8,\n    color=\"#AE3030\",\n    arrowprops={\"arrowstyle\": \"->\", \"color\": \"#AE3030\", \"lw\": 1.2},\n    va=\"center\",\n)\n\n# Phase region labels — color-coordinated with boundary curves\nax.text(225, 2e5, \"SOLID\", fontsize=10, fontweight=\"bold\", color=IMPRINT_PALETTE[0], ha=\"center\")\nax.text(390, 1.5e2, \"GAS\", fontsize=10, fontweight=\"bold\", color=IMPRINT_PALETTE[1], ha=\"center\")\nax.text(490, 3e6, \"LIQUID\", fontsize=10, fontweight=\"bold\", color=IMPRINT_PALETTE[2], ha=\"center\")\nax.text(\n    685,\n    critical_P * 10,\n    \"SUPERCRITICAL\\nFLUID\",\n    fontsize=8,\n    fontweight=\"bold\",\n    color=INK_MUTED,\n    ha=\"center\",\n    va=\"center\",\n)\n\n# Axes\nax.set_yscale(\"log\")\nax.set_xlim(190, 760)\nax.set_ylim(1e1, 1e9)\nax.set_xlabel(\"Temperature (K)\", fontsize=10, color=INK)\nax.set_ylabel(\"Pressure (Pa)\", fontsize=10, color=INK)\n\ntitle = \"phase-diagram-pt · python · seaborn · anyplot.ai\"\nax.set_title(title, fontsize=12, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=8, colors=INK_SOFT)\n\nsns.despine(ax=ax)\nax.yaxis.grid(True, color=INK, alpha=0.15, linewidth=0.6)\nax.legend(fontsize=8, loc=\"lower right\", framealpha=0.9, facecolor=ELEVATED_BG, edgecolor=INK_SOFT)\n\n# Save\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}