matplotlib

Previous topic

Example Code for Python

Next topic

Fluid Properties

This Page

Python PlottingΒΆ

Note

The python plotting API has been changed as of v4.0. The examples shown on this page use the new python plotting API. Examples using the old python plotting API can be found here Old Python Plotting.

The following example can be used to create a Temperature-Entropy plot for propane (R290):

from CoolProp.Plots import PropsPlot

ts_plot = PropsPlot('R290', 'Ts')
ts_plot.show()

(Source code, png)

../../_images/plotting-1.png

The following example can be used to create a Pressure-Enthalpy plot for R410A:

from CoolProp.Plots import PropsPlot

ph_plot = PropsPlot('R410A', 'Ph')
ph_plot.show()

(Source code, png)

../../_images/plotting-2.png

The available plots are:

PT Pressure-Temperature
PD Pressure-Density
PH Pressure-Enthalpy
PS Pressure-Entropy
TD Temperature-Density
TS Temperatre-Entropy
HS Enthalpy-Entropy

The following, more advanced example, can be used to draw lines of constant properties for n-Pentane. Note the different ways to invoke the CoolProp.Plots.Plots.PropsPlot.draw_isolines() function draw:

from CoolProp.Plots import PropsPlot

ref_fluid = 'n-Pentane'
ts_plot = PropsPlot(ref_fluid, 'Ts')
ts_plot.draw_isolines('Q', [0.3, 0.5, 0.7, 0.8])
ts_plot.draw_isolines('P', [100, 2000], num=5)
ts_plot.draw_isolines('D', [2, 600], num=7)
ts_plot.set_axis_limits([-2, 1.5, 200, 500])
ts_plot.show()

(Source code, png)

../../_images/plotting-3.png

Some of the commonly used Matplotlib functions, such as title(), xlabel() and ylabel() have been wrapped in the CoolProp.Plots.Plots.PropsPlot class to make the plotting of graphs a little simpler, for example:

from CoolProp.Plots import PropsPlot

ts_plot = PropsPlot('Water', 'Ts')
ts_plot.title('Ts Graph for Water')
ts_plot.xlabel(r's $[{kJ}/{kg K}]$')
ts_plot.ylabel(r'T $[K]$')
ts_plot.grid()
ts_plot.show()

(Source code, png)

../../_images/plotting-4.png

The following two examples show how the matplotlib.pyplot functions and matplotlib.pyplot.axes functions can also be used along side the CoolProp.Plots.Plots.PropsPlot class

from CoolProp.Plots import PropsPlot

ph_plot = PropsPlot('Water', 'Ph')
ax = ph_plot.axis
ax.set_yscale('log')
ax.text(400, 5500, 'Saturated Liquid', fontsize=15, rotation=40)
ax.text(2700, 3500, 'Saturated Vapour', fontsize=15, rotation=-100)
ph_plot.show()

(Source code, png)

../../_images/plotting-5.png
from matplotlib import pyplot
from CoolProp.Plots import PropsPlot

ref_fluid = 'R600a'
fig = pyplot.figure(1, figsize=(10, 10), dpi=100)
for i, gtype in enumerate(['PT', 'PD', 'PS', 'PH', 'TD', 'TS', 'HS']):
    ax = pyplot.subplot(4, 2, i+1)
    if gtype.startswith('P'):
        ax.set_yscale('log')
    props_plot = PropsPlot(ref_fluid, gtype, axis=ax)
    props_plot.title(gtype)
    props_plot._draw_graph()
pyplot.tight_layout()
pyplot.show()

(Source code, png)

../../_images/plotting-6.png