Skip to content

Instantly share code, notes, and snippets.

@bungernut
Last active January 12, 2022 03:50
Show Gist options
  • Save bungernut/050f4f2d4f13d9e78df2145c0ff1dd44 to your computer and use it in GitHub Desktop.
Save bungernut/050f4f2d4f13d9e78df2145c0ff1dd44 to your computer and use it in GitHub Desktop.
Vapor Pressure Plot from NIST Data
!apt install texlive-fonts-recommended texlive-fonts-extra cm-super dvipng
import matplotlib.pyplot as plt
plt.rcParams['text.usetex'] = True
import numpy as np
from scipy.optimize import minimize
from google.colab import files
from requests import get
import pandas as pd
from bs4 import BeautifulSoup
url="https://webbook.nist.gov/cgi/fluid.cgi?Action=Load&ID=C7440633&Type=SatP&Digits=5&THigh=180&TLow=161.4&TInc=.1&RefState=DEF&TUnit=K&PUnit=bar&DUnit=mol%2Fl&HUnit=kJ%2Fmol&WUnit=m%2Fs&VisUnit=uPa*s&STUnit=N%2Fm"
raw_html = get(url).content
html = BeautifulSoup(raw_html, 'html.parser')
table = html.findAll("table")
xe_data = pd.read_html(table[1].prettify())[0]
#print(xe_data.columns)
raw_html = get('https://webbook.nist.gov/cgi/cbook.cgi?ID=C10043922&Units=SI&Mask=4#Thermo-Phase').content
rn_html = BeautifulSoup(raw_html, 'html.parser')
table = rn_html.find("table", attrs={'aria-label': 'Antoine Equation Parameters'})
rn_data = pd.read_html(table.prettify())[0]
#rn_data
CB_color = ['#377eb8', '#ff7f00', '#4daf4a',
'#f781bf', '#a65628', '#984ea3',
'#999999', '#e41a1c', '#dede00']
fig, ax1 = plt.subplots(figsize=(6,4))
ax2 = ax1.twinx()
ax1.plot(xe_data['Temperature (K)'],xe_data['Pressure (bar)'],c=CB_color[0],label="Xe")
rn_P = np.power(10,[rn_data["A"] - (rn_data["B"]/(i + rn_data["C"])) for i in xe_data['Temperature (K)']]).T[0]
ax1.plot(xe_data['Temperature (K)'], rn_P,c=CB_color[3],label="Rn")
ax2.plot(xe_data['Temperature (K)'], rn_P / xe_data['Pressure (bar)'].to_numpy(),
ls="--",c=CB_color[2],label="Ratio")
ax1.legend(loc="center left")
ax2.legend(loc="center right")
ax1.set_ylabel("Vapor Pressure (Bar)")
ax2.set_ylabel(r"$\alpha$ Rn/Xe Vapor Pressure Ratio")
ax1.set_ylim(bottom=0)
ax1.set_xlabel("Temperature (K)")
plt.tight_layout()
plt.savefig("XeRn_VaporPress.png",dpi=200)
files.download("XeRn_VaporPress.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment