Co2-Properties

CoolProp Example - CO2 Density

#imports
import CoolProp.CoolProp as cp
import numpy as np
import pandas as pd
import hvplot.pandas
#import holoviews as hv

Density function (calls CoolProp)

#fucntion definition
def density(P,T,fluid):
    return cp.PropsSI('D', 'T', (T-32)*5/9 + 273.15, 'P', P*6894.75728, fluid)
densityfunc=np.vectorize(density)

Making of the density Plot

fluid='CO2'
P_psi= np.arange(400,5400,25.)
T_F  = np.arange(20,320,20.)

T, P = np.meshgrid(T_F, P_psi, sparse=False)
d=densityfunc(P,T,fluid)

df = pd.DataFrame(d.T, columns = P_psi, index = [str(i)+' F' for i in T_F])
plt=df.T.hvplot(
    kind='line',
    color=T_F.size*['k'],
    alpha=list(np.linspace(1,.3,T_F.size)),
    xlabel='Pressure [psi]', ylabel='Density [kg/m^3]', height=500, width=780,
    title=f'{fluid} density along isotherm',grid=True
)
#hv.save(plt, f"{fluid}_density.html", backend="bokeh")
plt

Documentation: http://www.coolprop.org/