# CoolProp Plot in Julia

**URL:** <https://discourse.julialang.org/t/coolprop-plot-in-julia/58204>\
**Category:** New to Julia\
**Tags:** package, plotting\
**Created:** [March 30, 2021, 6:05am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204 "2021-03-30T06:05:04Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [March 30, 2021, 6:05am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/1 "2021-03-30T06:05:04Z")

</div>

How to reproduce this example in Julia:  
[propane (R-290)](http://coolprop.sourceforge.net/coolprop/python-plotting.html)

```julia
import CoolProp
from CoolProp.Plots import PropertyPlot
plot = PropertyPlot('R290', 'ph')
plot.calc_isolines()
plot.show()

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 30, 2021, 7:10am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/2 "2021-03-30T07:10:28Z")

</div>

You could try using PyCall.

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [March 30, 2021, 7:56am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/3 "2021-03-30T07:56:38Z")

</div>

I managed to install in julia 1.5.4 CoolProp.jl

```julia
Julia>using CoolProp
[Info: Precompiling CoolProp [e084ae63-2819-5025-826e-f8e611a84251]

Julia>PropsSI("n-Butane", "rhomolar_critical")
08:46:54->>3922.769612987809

Julia>saturation_ancillary("R410A","I",1,"T", 300)
08:48:38->>0.004877519938463291

Julia>PropsSI("T","P",101325.0,"Q",0.0,"Water")
08:55:35->>373.1242958476844

Julia>PropsSI("T","P",101325.0,"Q",0.0,"Water")
08:56:51->>373.1242958476844

Julia>PropsSI("D", "T", 298.15, "P", 100e5, "CO2")
08:59:15->>817.6273812375758

```

Using PyCall will I be able to get the graphics? I have searched the Internet for an example developed in Julia. But without results !!!

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [March 30, 2021, 12:25pm UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/4 "2021-03-30T12:25:12Z")

</div>

> [@HerAdri](#):
>
> `from CoolProp.Plots import PropertyPlot`

```julia
Julia>ENV["PYCALL_JL_RUNTIME_PYTHON"] = Sys.which("python")
Julia>using PyCall
Julia>pyimport("sys").executable
Julia>@pyimport CoolProp.CoolProp as CP
Julia>mu_w= CP.PropsSI("V","T",273.15+22.0,"P",100,"H2O") # mu [Pa.s], T [K], P [kPa]
15:07:53->>9.613300658014403e-6

```

So far I have advanced with the installation of CoolProp in Python and make it run within the Julia 1.5.4 environment  
Could you guide me to achieve the graphic part of the example [shown above](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204)

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [March 30, 2021, 12:48pm UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/5 "2021-03-30T12:48:00Z")

</div>

```julia
ph_plot = CPP.PropertyPlot("R290", "ph")
ph_plot.calc_isolines();
ph_plot.show()

```

 ![PlotPy](https://global.discourse-cdn.com/julialang/original/3X/4/7/47e750341685094d5061401abd267a989a0b2fc8.jpeg)

```julia
Julia>ph_plot = CPP.PropertyPlot("R290", "ph")
15:38:19->>PyObject <CoolProp.Plots.Plots.PropertyPlot object at 
With the command, I get a lot of alerts:
Julia>ph_plot.calc_isolines()
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 5554182.916463, -1395.183008 with index (241,): unable to solve 1phase PY flash with Tmin=86.0392, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [-61.5215 J/mol/K] is below the minimum value of -61.5194289616 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 5944686.491989, -1395.183008 with index (242,): unable to solve 1phase PY flash with Tmin=86.0754, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [-61.5215 J/mol/K] is below the minimum value of -61.5168139473 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 6362645.598741, -1395.183008 with index (243,): unable to solve 1phase PY flash with Tmin=86.1141, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [-61.5215 J/mol/K] is below the minimum value of -61.5139955242 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 6809990.580620, -1395.183008 with index (244,): unable to solve 1phase PY flash with Tmin=86.1556, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [-61.5215 J/mol/K] is below the minimum value of -61.5109566397 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 7288787.500172, -1395.183008 with index (245,): unable to solve 1phase PY flash with Tmin=86.1999, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [-61.5215 J/mol/K] is below the minimum value of -61.5076786622 J/mol/K
  warnings.warn(

```

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [March 31, 2021, 5:04am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/6 "2021-03-31T05:04:47Z")

</div>

```julia
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 3451904.204494,
6393.882263 with index (234,): unable to solve 1phase PY flash with Tmin=358.414, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [281.942 J/mol/K] is above the maximum value of 238.143838756 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 3694600.736910,
6393.882263 with index (235,): unable to solve 1phase PY flash with Tmin=362.14,
Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [281.942 J/mol/K] is above the maximum value of 237.549744409 J/mol/K

                                           #*** 
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:608: UserWarning: Please use "calc_sat_range" to calculate saturation and isoquality lines. Input ranges are discarded.

C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Plots.py:217: UserWarning: Detected an incomplete phase envelope, fixing
it numerically.
  warnings.warn("Detected an incomplete phase envelope, fixing it numerically.")

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 31, 2021, 6:03am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/7 "2021-03-31T06:03:20Z")

</div>

> [@HerAdri](#):
>
> Using PyCall will I be able to get the graphics?

I haven’t heard of CoolProps, but if there is a Julia version of it, you presumably don’t need to use PyCall. The reason for suggesting that was probably that you didn’t at first mention that there exists a CoolProps.jl. Without a Julia version or wrapper you would need PyCall.

If you need a Julia plotting library, there are several to choose from, perhaps the most widely used is Plots.jl.

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [March 31, 2021, 6:07am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/8 "2021-03-31T06:07:15Z")

</div>

```julia
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 3451904.204494,
6393.882263 with index (234,): unable to solve 1phase PY flash with Tmin=358.414, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [281.942 J/mol/K] is above the maximum value of 238.143838756 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 3694600.736910,
6393.882263 with index (235,): unable to solve 1phase PY flash with Tmin=362.14,
Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [281.942 J/mol/K] is above the maximum value of 237.549744409 J/mol/K

                                           #*** 
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:608: UserWarning: Please use "calc_sat_range" to calculate saturation and isoquality lines. Input ranges are discarded.

C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Plots.py:217: UserWarning: Detected an incomplete phase envelope, fixing
it numerically.
  warnings.warn("Detected an incomplete phase envelope, fixing it numerically.")

```

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [March 31, 2021, 6:22am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/9 "2021-03-31T06:22:16Z")

</div>

I read about the CoolProp.jl package  
And I could not install it by following the instructions in the [package](https://github.com/CoolProp/CoolProp.jl).  
I only got through the “GitHub Desktop”  
I show the successful installation:

```julia
 [e084ae63] CoolProp v0.0.0 `C:\Users\hermesr\Documents\GitHub\CoolProp.jl#master`

```

[above I show the use of the package](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/3)  
But I have not found help from the package that shows the use of it and handling of the graphics, isolines …  
Please could you guide me to achieve the graph shown in [Python Plotting](http://coolprop.sourceforge.net/coolprop/python-plotting.html)

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 31, 2021, 6:45am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/10 "2021-03-31T06:45:42Z")

</div>

Unfortunately, I know nothing about CoolProps or how to plot with it. But what do you mean by this:

> [@HerAdri](#):
>
> And I could not install it by following the instructions in the [package](https://github.com/CoolProp/CoolProp.jl).  
> I only got through the “GitHub Desktop”

?  
Did you install it inside Julia, or some other way? You should install it using the Julia package manager, `Pkg`. If the installation instructions don’t work, then perhaps you can contact the package author (of the Julia wrapper) in the github repository, by opening an issue.

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [March 31, 2021, 8:46am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/11 "2021-03-31T08:46:30Z")

</div>

> [@DNF](#):
>
> you install it inside Julia

Yes, I install it inside Julia

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [April 1, 2021, 4:17am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/12 "2021-04-01T04:17:33Z")

</div>

In the following line of code I receive the following alert:

```julia
@pyimport CoolProp.CoolProp as CP
@pyimport CoolProp.Plots as CPP #StateContainer

T0 = 300.000; p0 = 200000.000; h0 = 112745.749; s0 = 393.035;
cycle_states = CPP.StateContainer()
cycle_states[1,"H"] = h0
ERROR: MethodError: no method matching setindex!(::PyObject, ::Float64, ::Int64,
::String)
Closest candidates are:
  setindex!(::PyObject, ::Any, ::Integer) at deprecated.jl:70
  setindex!(::PyObject, ::Any, ::Integer, ::Integer) at deprecated.jl:70
  setindex!(::PyObject, ::Any, ::Integer...) at deprecated.jl:70
  ...
Stacktrace:
 [1] top-level scope at REPL[197]:1

```

the original code from Python is the following:

```julia
In [3]: from CoolProp.Plots import StateContainer

In [4]: T0 = 300.000; p0 = 200000.000; h0 = 112745.749; s0 = 393.035

In [5]: cycle_states = StateContainer()

In [6]: cycle_states[0,'H'] = h0

```

how to write correctly in Julia this line of code. !!!

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [April 2, 2021, 4:29am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/13 "2021-04-02T04:29:23Z")

</div>

[Solution](https://stackoverflow.com/questions/66888149/coolprop-script-from-python-to-julia/66911000#66911000)  
[https://stackoverflow.com/a/66911000/8409550](https://stackoverflow.com/a/66911000/8409550)

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [April 2, 2021, 6:31am UTC](https://discourse.julialang.org/t/coolprop-plot-in-julia/58204/14 "2021-04-02T06:31:06Z")

</div>

How to achieve the following command: print (cycle states). I have tried @pycall (cycle\_states)  
ERROR: ArgumentError: Usage: @pycall func (args …) :: T;  
get! (cycle\_states)  
ERROR: MethodError: no method matching get! (:: PyObject)  
print(cycle states)  
PyObject \<CoolProp.Plots.SimpleCycles.StateContainer object at 0x0000000007E70AF0\>
