# Makie volume animation froze!

**URL:** <https://discourse.julialang.org/t/makie-volume-animation-froze/43707>\
**Category:** New to Julia\
**Tags:** plotting, makie, animations\
**Created:** [July 26, 2020, 11:20am UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707 "2020-07-26T11:20:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [July 26, 2020, 11:20am UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/1 "2020-07-26T11:20:58Z")

</div>

Super simple Makie animation question. I am just trying to make a video from a `volume()` render of a field. I tried

```julia
a = zeros(n,n,n)
scene = volume(a)
record("file.mp4",1:100) do i
   func!(a)
   scene = volume!(scene,a)
end

```

But this froze my computer!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 26, 2020, 11:45am UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/2 "2020-07-26T11:45:34Z")

</div>

That’s because you have added a hundred volumes to your scene.

The way to do it is with Observables (Nodes in Makie):

```julia
a = Node(zeros(n, n, n))

scene = volume(a)

# Then in the record loop:

a[] = func(a[])

```

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [July 26, 2020, 1:09pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/3 "2020-07-26T13:09:57Z")

</div>

Or:

```julia
a = zeros(n,n,n)
scene = volume(a)
vol_plot = scene[end] # end --> last plot
record("file.mp4",1:100) do i
   func!(a)
   vol_plot[1] = a # update values passed by first argument
end

```

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [July 26, 2020, 5:03pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/4 "2020-07-26T17:03:46Z")

</div>

This worked. Is there somewhere that explains `scene[end][1]`?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 27, 2020, 6:12am UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/5 "2020-07-27T06:12:22Z")

</div>

It means last plot in the scene, first positional argument of that plot. As positional arguments are always internally converted to observables this lets you change the observable as if you had created it yourself and passed it in

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [July 27, 2020, 8:58am UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/6 "2020-07-27T08:58:13Z")

</div>

[http://makie.juliaplots.org/dev/animation.html](http://makie.juliaplots.org/dev/animation.html)  
[http://makie.juliaplots.org/dev/interaction.html](http://makie.juliaplots.org/dev/interaction.html)

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [July 27, 2020, 9:23am UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/7 "2020-07-27T09:23:21Z")

</div>

Thanks. The Node documentation is clear now. I didn’t understand that the empty index `a[]` was triggering the update. Is there a more explicit way to do that?

The only place on the animation page I see the `[end]`-style used is in this example.

[http://makie.juliaplots.org/dev/animation.html#More-complex-examples](http://makie.juliaplots.org/dev/animation.html#More-complex-examples)

where index `[3]` is used since the third argument was `z`. Is that right?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [July 27, 2020, 9:28am UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/8 "2020-07-27T09:28:30Z")

</div>

> [@weymouth](#):
>
> where index `[3]` is used since the third argument was `z` . Is that right?

exactly!

> Is there a more explicit way to do that?

not really. The syntax to update a node (observable) is this:

```julia
observable[] = new_value

```

Like updating a reference 😉  
Which is the key abstraction in Observables.jl. You can think of it as references with event listeners!

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [July 27, 2020, 1:16pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/9 "2020-07-27T13:16:01Z")

</div>

Thanks for the help. Here’s a couple of samples  
 ![ezgif.com-video-to-gif](https://global.discourse-cdn.com/julialang/original/3X/0/f/0f11d605479193cc3bbae094aec8289b7bf13c19.gif)  
 ![ezgif.com-gif-maker](https://global.discourse-cdn.com/julialang/original/3X/a/0/a08368091a2fb14cb22a600b469efac96280d6f8.gif)

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [July 27, 2020, 1:57pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/10 "2020-07-27T13:57:08Z")

</div>

Was that made with WaterLily, or what’s the source?

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [July 27, 2020, 3:38pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/11 "2020-07-27T15:38:28Z")

</div>

WaterLily. I’ve add these two cases in the examples.

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [July 27, 2020, 3:48pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/12 "2020-07-27T15:48:35Z")

</div>

Impressive !  
Do you plan to add a mathematical description of the code (the immersed boundary method) ?

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [July 27, 2020, 5:06pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/13 "2020-07-27T17:06:04Z")

</div>

Well, the paper is here: [Accurate Cartesian-grid simulations of near-body flows at intermediate Reynolds numbers - ePrints Soton](https://eprints.soton.ac.uk/369635/). I’ve only implemented first-order in WaterLily so far.

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [July 27, 2020, 5:17pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/14 "2020-07-27T17:17:37Z")

</div>

Thank you very much !  
It could be useful to insert the link in the WaterLily’s README.jl

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [July 27, 2020, 5:23pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/15 "2020-07-27T17:23:03Z")

</div>

You’re right; I shouldn’t point to a paywall! Done.

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [August 2, 2020, 10:57pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/16 "2020-08-02T22:57:01Z")

</div>

Sorry to resurrect this, but I’ve got another _n00b_ issue. It seems like all the volume plot methods are set up for sequential data (`colorrange=(0,1)` where 0 is background and 1 is what we want to visualize) but what about divergent data? Is there something for `colorrange=(-1,1)` where 0 is background and +1 is one extreme and -1 is the other?

Alternatively, is there some way to achieve `isovalue=(-1,1)`? Doing two plots with `isovalue=-1` and `isovalue=1` doesn’t work since the second one just overlays the first and so they don’t line up three-dimensionally as they should.

Twitter post for context:

> <https://twitter.com/abhijitmitra_4u/status/1290025453349040133?s=20>

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [August 3, 2020, 9:02am UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/17 "2020-08-03T09:02:22Z")

</div>

with contour, you basically get multiple iso value plots in one plot, with correct transparency:

```julia
contour(rand(4, 4, 4), levels=[-1.0, 1.0])

```

> Is there something for `colorrange=(-1,1)` where 0 is background and +1 is one extreme and -1 is the other?

I’m not sure what you mean … You can use whatever colormap you want 😉  
`colormap=any_array_of_colors`

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [August 3, 2020, 11:53am UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/18 "2020-08-03T11:53:45Z")

</div>

`contour`🤦‍♂️ (I guess I was more tired than I thought last night.)

> I’m not sure what you mean … You can use whatever colormap you want 😉  
> `colormap=any_array_of_colors`

For the volume rendering, I’m not looking for a `color` map, but an `alpha` or `absorption` map. So, maybe like `absorption=[-1,1]` so that regions that are both below -1 and above 1 show up in the volume plot (as different colors), but not regions with values around 0.

For example, I coded this up long ago (in Fortran, because I’m a masochist)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/e/eed61fa7d258742be72ffb5495b4654e143dd69b.jpeg)

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [August 3, 2020, 2:18pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/19 "2020-08-03T14:18:25Z")

</div>

Here is version using `:mip`

 ![mpi](https://global.discourse-cdn.com/julialang/original/3X/c/0/c022cc6c779bfeef681078078f92163ac78ba191.png)  
And here is the version using `:absorption`  
 ![abs](https://global.discourse-cdn.com/julialang/original/3X/1/6/16bd2334a9c8dca585b98bb0dc56ee3e8813b0ee.png)  
Neither shows the structures very clearly.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [August 3, 2020, 4:36pm UTC](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/20 "2020-08-03T16:36:58Z")

</div>

How does it look with with `contour`?  
Also, you can use transparent colors e.g:

```julia
cmap = :thermal
colors = to_colormap(cmap)
cmap_alpha = RGBAf0.(colors, LinRange(0, 1, length(colors)))

```

[Next page](https://discourse.julialang.org/t/makie-volume-animation-froze/43707.md?page=2)
