# Create gif

**URL:** <https://discourse.julialang.org/t/create-gif/59029>\
**Category:** New to Julia\
**Tags:** plot\
**Created:** [April 11, 2021, 11:04am UTC](https://discourse.julialang.org/t/create-gif/59029 "2021-04-11T11:04:47Z")\
**Posts on this page:** 10\
**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:** [April 11, 2021, 11:04am UTC](https://discourse.julialang.org/t/create-gif/59029/1 "2021-04-11T11:04:48Z")

</div>

I need to create an animated image (gif) from this script from a set of temperatures  
[T0 -|- T2]:

| [EvptTemp | CndsTemp] |
| --- | --- |
| 55 | 33 |
| 55 | 34 |
| 55 | 35 |
| 55 | 36 |
| 55 | 37 |
| 55 | 38 |
| 55 | 39 |
| 55 | 40 |
| 55 | 41 |
| 55 | 42 |
| 55 | 43 |
| 55 | 44 |
| 55 | 45 |
| 55 | 46 |
| 55 | 47 |
| 55 | 48 |
| 55 | 49 |
| The problem for me is that CoolProop | |
| generates alerts during the run, before generating the diagram. | |

```julia
using PyCall

pyimport("sys").executable

@pyimport CoolProp.CoolProp as CP

@pyimport CoolProp.Plots as CPP #StateContainer

pp = CPP.PropertyPlot("R32", "PH", unit_system="KSI")

pp.title("R32 log p-h Diagramm")

pp.set_axis_limits([-40, 700, 0, 15000])

pp.xlabel("h [kJ/kg]")

pp.ylabel("P [kPa]")

pp.calc_isolines(num=20)

cycle = CPP.SimpleCompressionCycle("R32", "PH", unit_system="KSI")

T0 = 33+273.15

pp.state.update(CP.QT_INPUTS,0.0,T0-0.02) 

p0 = pp.state.keyed_output(CP.iP)

T2 = 55+273.15

pp.state.update(CP.QT_INPUTS,1.0,T2+0.02)

p2 = pp.state.keyed_output(CP.iP)

pp.calc_isolines(CP.iT, [T0-273.15,T2-273.15], num=2)

cycle.simple_solve(T0, p0, T2, p2, 0.7, SI=true)

cycle.steps = 50

sc = cycle.get_state_changes()

pp.draw_process(sc)

@pyimport matplotlib.pyplot as plt

plt.close(cycle.figure)

pp.show()

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [April 11, 2021, 12:14pm UTC](https://discourse.julialang.org/t/create-gif/59029/2 "2021-04-11T12:14:49Z")

</div>

What “alerts” do you get?

---

<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 11, 2021, 12:42pm UTC](https://discourse.julialang.org/t/create-gif/59029/3 "2021-04-11T12:42:33Z")

</div>

![Alertas CoolProp Julia PyCall](https://global.discourse-cdn.com/julialang/original/3X/0/1/01fb7500eda41e3828644254ced2c3308260f36d.jpeg)

```julia

C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 11639762.774893, 55.000000 with index (244,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root. Function values are [18200507441268.304688,17.009243]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 12245416.329262, 55.000000 with index (245,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root. Function values are [17300317384293.095703,16.118513]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 12882583.947535, 55.000000 with index (246,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root. Function values are [16444650379287.328125,15.271838]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 13552905.405813, 55.000000 with index (247,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root. Function values are [15631304333324.744141,14.467039]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 14258105.802918, 55.000000 with index (248,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root. Function values are [14858186068143.455078,13.702045]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 15000000.000000, 55.000000 with index (249,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root. Function values are [14123305933268.613281,12.974888]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:683: UserWarning: Poor data quality, there are not enough valid entries for x (0.000000/250.000000) or y (250.000000/250.000000).
  warnings.warn(

```

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [April 11, 2021, 12:59pm UTC](https://discourse.julialang.org/t/create-gif/59029/4 "2021-04-11T12:59:42Z")

</div>

You might try doing animations and gifs with the Plots package. I’ve found that very simple and easy. [Animations · Plots](https://docs.juliaplots.org/latest/animations/)

---

<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 12, 2021, 8:06am UTC](https://discourse.julialang.org/t/create-gif/59029/5 "2021-04-12T08:06:20Z")

</div>

How to save PyCall’s pp.show () object, as a Julia image or plot object? And in this way use the gif macro

---

<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 12, 2021, 8:57am UTC](https://discourse.julialang.org/t/create-gif/59029/6 "2021-04-12T08:57:22Z")

</div>

In this way the images are created and saved in a file. how to get a gif from these images?

```julia
using PyCall

pyimport("sys").executable

@pyimport CoolProp.CoolProp as CP

@pyimport CoolProp.Plots as CPP #StateContainer

TT = [[55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55];

 [33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49]]

n=size(TT,2)

for i in 1:n

pp = CPP.PropertyPlot("R32", "PH", unit_system="KSI")

pp.title("R32 log p-h Diagramm")

pp.set_axis_limits([-40, 700, 0, 15000])

pp.xlabel("h [kJ/kg]")

pp.ylabel("P [kPa]")

pp.calc_isolines(num=20)

cycle = CPP.SimpleCompressionCycle("R32", "PH", unit_system="KSI")

T0 = TT[2,i]+273.15

pp.state.update(CP.QT_INPUTS,0.0,T0-0.02) 

p0 = pp.state.keyed_output(CP.iP)

T2 = TT[1,i]+273.15

pp.state.update(CP.QT_INPUTS,1.0,T2+0.02)

p2 = pp.state.keyed_output(CP.iP)

pp.calc_isolines(CP.iT, [T0-273.15,T2-273.15], num=2)

cycle.simple_solve(T0, p0, T2, p2, 0.7, SI=true)

cycle.steps =50

sc = cycle.get_state_changes()

pp.draw_process(sc)

@pyimport matplotlib.pyplot as plt

plt.close(cycle.figure)

#pp.show()

file=string("C:/Users/hermesr/Documents/R32_",i,".jpg")

pp.savefig(file)

end

```

---

<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 12, 2021, 12:09pm UTC](https://discourse.julialang.org/t/create-gif/59029/7 "2021-04-12T12:09:59Z")

</div>

Thanks to reading the link [Plotting a sequence of images as a gif](https://discourse.julialang.org/t/plotting-a-sequence-of-images-as-a-gif/23808)

![test](https://global.discourse-cdn.com/julialang/original/3X/7/e/7e61f54ee1f1da8450327a2806bbb757b278040e.gif)

```julia
using FileIO, ImageMagick
using PyCall
pyimport("sys").executable
@pyimport CoolProp.CoolProp as CP
@pyimport CoolProp.Plots as CPP #StateContainer

TT = [[55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55];
[33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49]]
n=size(TT,2)
file=""
i=1

for i in 1:n
pp = CPP.PropertyPlot("R32", "PH", unit_system="KSI")
pp.title("R32 log p-h Diagramm")
pp.set_axis_limits([-40, 700, 0, 15000])
pp.xlabel("h [kJ/kg]")
pp.ylabel("P [kPa]")
pp.calc_isolines(num=20)

cycle = CPP.SimpleCompressionCycle("R32", "PH", unit_system="KSI")
T0 = TT[2,i]+273.15
pp.state.update(CP.QT_INPUTS,0.0,T0-0.02) 
p0 = pp.state.keyed_output(CP.iP)
T2 = TT[1,i]+273.15
pp.state.update(CP.QT_INPUTS,1.0,T2+0.02)
p2 = pp.state.keyed_output(CP.iP)
pp.calc_isolines(CP.iT, [T0-273.15,T2-273.15], num=2)
cycle.simple_solve(T0, p0, T2, p2, 0.7, SI=true)
cycle.steps =50
sc = cycle.get_state_changes()

pp.draw_process(sc)
@pyimport matplotlib.pyplot as plt
plt.close(cycle.figure)
#pp.show()
ss=string("C:/Users/hermesr/Documents/R32_",i,".jpg")
pp.savefig(ss)
end

A = load("C:/Users/hermesr/Documents/R32_1.jpg");
for i in 2:n
A = cat(A, load("C:/Users/hermesr/Documents/R32_"*string(i)*".jpg"), dims=3)
end
save("C:/Users/hermesr/Documents/test.gif", A)

```

---

<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 13, 2021, 4:47am UTC](https://discourse.julialang.org/t/create-gif/59029/8 "2021-04-13T04:47:48Z")

</div>

Help Me!  
In the first run the script I receive the following alert:

```julia
#pp.show()
       ss="C:/Users/hermesr/Documents/R410A_stM_"*string(i)*".jpg"
       pp.savefig(ss)
       end
ERROR: syntax: unsupported `const` declaration on local variable around C:\Users\hermesr\.julia\packages\PyCall\BD546\src\PyCall.jl:594
Stacktrace:
 [1] top-level scope at REPL[12]:1

```

I have solved it as follows:  
i = 1 is initialized.  
the line # pp.show () is activated, that is, pp.show ().  
And I run the content inside the for loop.  
after that # pp.show (), and performed the run of the for loop and the following lines.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [April 13, 2021, 10:42pm UTC](https://discourse.julialang.org/t/create-gif/59029/9 "2021-04-13T22:42:21Z")

</div>

1. Don’t use `@pyimport` within the `for` loop.
2. You might want to do something like `plt = pyimport("matplotlib.pyplot")`. I still recommend putting that outside of the `for` loop.

---

<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 27, 2021, 9:54am UTC](https://discourse.julialang.org/t/create-gif/59029/10 "2021-04-27T09:54:02Z")

</div>

How to close figure 1 from the script?

 ![Close fig1](https://global.discourse-cdn.com/julialang/original/3X/f/b/fbc0af14ba9bc31a061554151251bccf8929668f.jpeg)
