{"spec_id":"phase-diagram-pt","library":"makie","language":"julia","code":"# anyplot.ai\n# phase-diagram-pt: Thermodynamic Phase Diagram (Pressure-Temperature)\n# Library: makie 0.22.10 | Julia 1.11.9\n# Quality: 90/100 | Created: 2026-06-08\n\nusing CairoMakie\nusing Colors\nusing Random\n\nRandom.seed!(42)\n\n# Theme tokens (Imprint palette — see prompts/default-style-guide.md)\nconst THEME       = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG     = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst ELEVATED_BG = THEME == \"light\" ? colorant\"#FFFDF6\" : colorant\"#242420\"\nconst INK         = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT    = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\nconst INK_MUTED   = THEME == \"light\" ? colorant\"#6B6A63\" : colorant\"#A8A79F\"\nconst IMPRINT_PALETTE = [\n    colorant\"#009E73\",  # 1 — brand green (vaporization / liquid-gas boundary)\n    colorant\"#C475FD\",  # 2 — lavender    (melting / solid-liquid boundary)\n    colorant\"#4467A3\",  # 3 — blue        (sublimation / solid-gas boundary)\n]\n\n# Water physical constants\nconst T_tp = 273.16    # triple point temperature (K)\nconst P_tp = 611.73    # triple point pressure (Pa)\nconst T_c  = 647.1     # critical point temperature (K)\nconst P_c  = 22.064e6  # critical point pressure (Pa)\nconst R    = 8.314     # universal gas constant (J·mol⁻¹·K⁻¹)\n\n# Clausius-Clapeyron effective latent heats\n# L_lg fitted so the curve passes through both (T_tp, P_tp) and (T_c, P_c)\nconst L_lg = 41210.0  # J/mol — vaporization\nconst L_sg = 51300.0  # J/mol — sublimation\n\n# Vaporization curve: triple point → critical point\nT_lg = range(T_tp, T_c; length = 200)\nP_lg = P_tp .* exp.(-L_lg / R .* (1.0 ./ T_lg .- 1.0 / T_tp))\n\n# Sublimation curve: low temperature → triple point\nT_sg = range(220.0, T_tp; length = 100)\nP_sg = P_tp .* exp.(-L_sg / R .* (1.0 ./ T_sg .- 1.0 / T_tp))\n\n# Melting curve: triple point → high pressure (water's anomalous negative slope)\n# dP/dT ≈ -13.5 MPa/K because liquid water is denser than ice (ΔV < 0)\nconst melt_slope = -13.5e6    # Pa/K\nconst P_melt_top = 5.0e7      # Pa — top of displayed y range\nT_sl_min = T_tp + (P_melt_top - P_tp) / melt_slope\nT_sl = range(T_sl_min, T_tp; length = 80)\nP_sl = P_tp .+ melt_slope .* (T_sl .- T_tp)\n\n# Grid colour: theme-adaptive ink at 12 % opacity\nconst GRID_COLOR = RGBAf(Float32(INK.r), Float32(INK.g), Float32(INK.b), 0.12f0)\n\n# Figure\nfig = Figure(\n    size            = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = \"Water Phase Diagram · phase-diagram-pt · julia · makie · anyplot.ai\",\n    titlesize          = 20,\n    titlecolor         = INK,\n    xlabel             = \"Temperature (K)\",\n    ylabel             = \"Pressure (Pa)\",\n    xlabelcolor        = INK,\n    ylabelcolor        = INK,\n    xlabelsize         = 14,\n    ylabelsize         = 14,\n    xticklabelcolor    = INK_SOFT,\n    yticklabelcolor    = INK_SOFT,\n    xtickcolor         = INK_SOFT,\n    ytickcolor         = INK_SOFT,\n    xticklabelsize     = 12,\n    yticklabelsize     = 12,\n    backgroundcolor    = PAGE_BG,\n    topspinevisible    = false,\n    rightspinevisible  = false,\n    leftspinecolor     = INK_SOFT,\n    bottomspinecolor   = INK_SOFT,\n    yscale             = log10,\n    limits             = (220.0, 680.0, 1.0, 5.0e7),\n    xgridcolor         = GRID_COLOR,\n    ygridcolor         = GRID_COLOR,\n    xminorgridvisible  = false,\n    yminorgridvisible  = false,\n)\n\n# Supercritical fluid region: subtle shaded polygon (behind curves)\nconst SC_FILL = RGBAf(Float32(INK_MUTED.r), Float32(INK_MUTED.g), Float32(INK_MUTED.b), 0.08f0)\npoly!(ax, Point2f[(T_c, P_c), (680.0, P_c), (680.0, 5.0e7), (T_c, 5.0e7)];\n    color = SC_FILL, strokewidth = 0)\n\n# Phase boundary lines\nlines!(ax, T_lg, P_lg; color = IMPRINT_PALETTE[1], linewidth = 3.0, label = \"Liquid–Gas\")\nlines!(ax, T_sl, P_sl; color = IMPRINT_PALETTE[2], linewidth = 3.0, label = \"Solid–Liquid\")\nlines!(ax, T_sg, P_sg; color = IMPRINT_PALETTE[3], linewidth = 3.0, label = \"Solid–Gas\")\n\n# Triple point and critical point markers\nscatter!(ax, [T_tp], [P_tp]; color = INK, markersize = 16, marker = :circle, strokewidth = 0)\nscatter!(ax, [T_c],  [P_c];  color = INK, markersize = 18, marker = :star5,  strokewidth = 0)\n\n# Annotations: special points\ntext!(ax, T_tp + 5.0, P_tp * 10.0;\n    text     = \"Triple Point\\n(273.16 K, 611.7 Pa)\",\n    color    = INK,\n    fontsize = 13,\n    align    = (:left, :bottom),\n)\ntext!(ax, T_c - 5.0, P_c * 0.38;\n    text     = \"Critical Point\\n(647.1 K, 22.1 MPa)\",\n    color    = INK,\n    fontsize = 13,\n    align    = (:right, :top),\n)\n\n# Phase region labels\ntext!(ax, 248.0, 2.0e4;\n    text     = \"SOLID\",\n    color    = INK_MUTED,\n    fontsize = 16,\n    font     = :bold,\n    align    = (:center, :center),\n)\ntext!(ax, 430.0, 8.0e6;\n    text     = \"LIQUID\",\n    color    = INK_MUTED,\n    fontsize = 16,\n    font     = :bold,\n    align    = (:center, :center),\n)\ntext!(ax, 440.0, 1.5e3;\n    text     = \"GAS\",\n    color    = INK_MUTED,\n    fontsize = 16,\n    font     = :bold,\n    align    = (:center, :center),\n)\ntext!(ax, 662.0, 3.2e7;\n    text     = \"SUPER-\\nCRITICAL\\nFLUID\",\n    color    = INK_MUTED,\n    fontsize = 13,\n    align    = (:center, :center),\n)\n\n# Legend\naxislegend(ax;\n    position        = :rb,\n    framevisible    = true,\n    framecolor      = INK_SOFT,\n    backgroundcolor = ELEVATED_BG,\n    labelcolor      = INK,\n    labelsize       = 12,\n    patchsize       = (30, 12),\n)\n\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}