# On-the-fly Animation in IJulia Notebooks

**URL:** <https://discourse.julialang.org/t/on-the-fly-animation-in-ijulia-notebooks/524>\
**Category:** Visualization\
**Created:** [November 23, 2016, 2:32pm UTC](https://discourse.julialang.org/t/on-the-fly-animation-in-ijulia-notebooks/524 "2016-11-23T14:32:42Z")\
**Posts on this page:** 6\
**Page:** 3

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [February 26, 2017, 11:26pm UTC](https://discourse.julialang.org/t/on-the-fly-animation-in-ijulia-notebooks/524/41 "2017-02-26T23:26:58Z")

</div>

I would like to do updating like this for a histogram; the difficulty there is that I need to give the coordinates of the boxes. Any hints for that case? I.e., how can I extract those coordinates?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 27, 2017, 6:00am UTC](https://discourse.julialang.org/t/on-the-fly-animation-in-ijulia-notebooks/524/42 "2017-02-27T06:00:39Z")

</div>

Can’t you just specify the edges yourself and pass them as a vector to `bins`? Then you are also certain they won’t jump around in your animation.  
If you want to calculate them from the data, the current algorithm in Plots does `linspace(extrema(x)..., bins + 1)`, though it is likely to change to `StatsBase.fit(StatsBase.Histogram, x, nbins = bins).edges[1]` in the near future, with bins having a default value of 30.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [February 27, 2017, 11:55am UTC](https://discourse.julialang.org/t/on-the-fly-animation-in-ijulia-notebooks/524/43 "2017-02-27T11:55:16Z")

</div>

The problem is rather that of then calculating the actual polygons ( (x, y) pairs) to pass in to update the drawing, as far as I can see.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 27, 2017, 2:00pm UTC](https://discourse.julialang.org/t/on-the-fly-animation-in-ijulia-notebooks/524/44 "2017-02-27T14:00:33Z")

</div>

You’re right. I was too fast on the trigger here.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 27, 2017, 2:31pm UTC](https://discourse.julialang.org/t/on-the-fly-animation-in-ijulia-notebooks/524/45 "2017-02-27T14:31:42Z")

</div>

Try

```julia
using Plots
default(show=:ijulia)
bins = collect(-3:3); ylims = (0, 400)
p = histogram(randn(1000), bins = bins, ylims = ylims)

for i in 1:10
    h = histogram(randn(1000), bins = bins, ylims = ylims);
    p[1] = h.series_list[1][:x], h.series_list[1][:y]
    sleep(0.2)
    p
end

```

Of course this suffers from the overhead of calling `histogram`

---

<div class="post-metadata">

**Author:** ![photor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/photor/32/14343_2.png) [@photor](https://discourse.julialang.org/u/photor)\
**Post date:** [April 27, 2020, 1:25am UTC](https://discourse.julialang.org/t/on-the-fly-animation-in-ijulia-notebooks/524/46 "2020-04-27T01:25:21Z")

</div>

So interesting!

[Previous page](https://discourse.julialang.org/t/on-the-fly-animation-in-ijulia-notebooks/524.md?page=2)
