# Juno and interactive plot

**URL:** <https://discourse.julialang.org/t/juno-and-interactive-plot/3989>\
**Category:** New to Julia\
**Created:** [May 30, 2017, 1:48pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989 "2017-05-30T13:48:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [May 30, 2017, 1:48pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/1 "2017-05-30T13:48:13Z")

</div>

Hi,

I am trying to update a juno plot (with Plots.gr()) in a for loop but it does not work.

Can you give me a hint on whether it is possible? (I saw that it is possible with GR directly by in an external window)

Thank you,

Romain

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [May 30, 2017, 2:27pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/2 "2017-05-30T14:27:35Z")

</div>

This works fine for me (in Atom 1.17.2):

```julia
using Plots
gr()
for n in 1:100
  histogram(randn(10000))
end

```

I’m on `Plots` and `GR` master.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 30, 2017, 3:17pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/3 "2017-05-30T15:17:04Z")

</div>

> [@rveltz](#):
>
> Can you give me a hint on whether it is possible? (I saw that it is possible with GR directly by in an external window)

Use the `gui()` command to open the external window. I believe GR’s GUI isn’t interactive (yet, but that’s a big promised feature 🙂)

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [May 30, 2017, 3:47pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/4 "2017-05-30T15:47:11Z")

</div>

Oh, is it working on the plot pane?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 30, 2017, 6:35pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/5 "2017-05-30T18:35:06Z")

</div>

Plot pane interactivity requires that the output is javascript (others plot a PNG). If you want plot pane interactivity, use PlotlyJS. GR should get plot pane interactivity as part of its big GUI update, but you’ll probably hear more about that at JuliaCon.

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [May 30, 2017, 7:09pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/6 "2017-05-30T19:09:04Z")

</div>

Yes, it’s working in the plot pane - the plot is updated while the loop is executing. **Real** interactivity coming soon …

---

<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:** [May 31, 2017, 3:22pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/7 "2017-05-31T15:22:15Z")

</div>

Depending on setup, you may need `gr(show = true)`. This plot is not interactive, by the way - it is just updated.

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [May 31, 2017, 4:51pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/8 "2017-05-31T16:51:41Z")

</div>

@jheinen Are you on Julia v0.6?

In Atom [Plots and GR are on Master, OSX environment] , the for loop does not update the plot pane at all:

```julia
using Plots
gr()
for n in 1:3
  sleep(0.2)
  histogram(randn(10000))
end

```

but this one does

```julia
using Plots
gr()
for n in 1:3
  sleep(0.2)
  histogram(randn(10000))
end
title!("Update!")

```

and it does it by showing the last plot and not the plot in between.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [May 31, 2017, 6:24pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/9 "2017-05-31T18:24:28Z")

</div>

You should use

```julia
using Plots
gr()
for n in 1:3
  sleep(0.2)
  display(histogram(randn(10000)))
end

```

Juno doesn’t display plots when you call `plot`, unless the result of the call to plot is actually shown somewhere (just like the REPL).

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [May 31, 2017, 7:21pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/10 "2017-05-31T19:21:41Z")

</div>

Excellent! Thank you.

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [May 31, 2017, 7:31pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/11 "2017-05-31T19:31:03Z")

</div>

Could you pls try the following code - just to ensure, that GR is working fine:

```julia
using GR
inline("atom")
for n in 1:100
  sleep(0.02)
  histogram(randn(10000))
end

```

BTW: The `sleep` command is not necessary - but we have to slow down the animation (GR is fast) 🙂

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [May 31, 2017, 7:36pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/12 "2017-05-31T19:36:02Z")

</div>

@jheinen

It works as well! Thank you a lot.

---

<div class="post-metadata">

**Author:** ![Tessereau\_Charline](https://avatars.discourse-cdn.com/v4/letter/t/90ced4/32.png) [@Tessereau\_Charline](https://discourse.julialang.org/u/Tessereau_Charline)\
**Post date:** [June 2, 2017, 10:48am UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/13 "2017-06-02T10:48:31Z")

</div>

Hi,  
I am trying to plot in real time with Julia  
I use this code

> using Plots  
> gr(show = :ijulia)  
> x = 0:0.01:2\*pi  
> for i in 1:200  
> plot(x, sin.(x + i / 10.0))  
> end

Sometimes it works. But most of the times I just get all the lines on a same plots at the end of the loop.  
Do you have any idea of what happens?  
Thank you

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [June 2, 2017, 11:26am UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/14 "2017-06-02T11:26:38Z")

</div>

Could you try to add a sleep command (`sleep(0.01)`) in the loop ?

… or, add a display command:  
`display(plot(x, sin.(x + i / 10.0)))`

This worked for me, e.g.:

```julia
using Plots
gr()
for i in 1:100
  display(histogram(randn(10000)))
end

```

---

<div class="post-metadata">

**Author:** ![Tessereau\_Charline](https://avatars.discourse-cdn.com/v4/letter/t/90ced4/32.png) [@Tessereau\_Charline](https://discourse.julialang.org/u/Tessereau_Charline)\
**Post date:** [June 2, 2017, 2:22pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/15 "2017-06-02T14:22:14Z")

</div>

> display

displays this :  
1-element Array{Any,1}:  
PyObject \<matplotlib.lines.Line2D object at 0x32549b5d0\>  
**at each step** of the loop… Do you have an idea of why?

> sleep(0.01)

does not change the output : still all the lines on the same plot at the end of the loop…

I use IJulia on a jupyter notebook, if this can help. Thank you !

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [June 2, 2017, 2:29pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/16 "2017-06-02T14:29:17Z")

</div>

In IJulia (Jupyter notebook), this works for me:

```julia
using Plots
gr(show=:ijulia)
for i in 1:100
  histogram(randn(10000))
end

```

---

<div class="post-metadata">

**Author:** ![Tessereau\_Charline](https://avatars.discourse-cdn.com/v4/letter/t/90ced4/32.png) [@Tessereau\_Charline](https://discourse.julialang.org/u/Tessereau_Charline)\
**Post date:** [June 2, 2017, 2:40pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/17 "2017-06-02T14:40:14Z")

</div>

This works :

> using Plots  
> gr(show=:ijulia)  
> for i in 1:100  
> histogram(randn(10000))  
> end

but not this :

> using Plots  
> gr(show=:ijulia)  
> x = 0:0.01:2\*pi  
> for i in 1:200  
> plot(x, sin.(x + i / 10.0))  
> end

Do you have any idea why? Thanks

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [June 2, 2017, 3:23pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/18 "2017-06-02T15:23:35Z")

</div>

There seems to be a limitation concerning the amount of data which can be transferred between the kernel and the notebook server. You can increase this limit with a command line option:

```bash
jupyter notebook --NotebookApp.iopub_data_rate_limit=10000000

```

Seems to be a new **feature** in the notebook protocol. 🙂

---

<div class="post-metadata">

**Author:** ![Tessereau\_Charline](https://avatars.discourse-cdn.com/v4/letter/t/90ced4/32.png) [@Tessereau\_Charline](https://discourse.julialang.org/u/Tessereau_Charline)\
**Post date:** [June 2, 2017, 3:56pm UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/19 "2017-06-02T15:56:22Z")

</div>

It does not change the result.  
I will try to look in that direction though.

---

<div class="post-metadata">

**Author:** ![Tessereau\_Charline](https://avatars.discourse-cdn.com/v4/letter/t/90ced4/32.png) [@Tessereau\_Charline](https://discourse.julialang.org/u/Tessereau_Charline)\
**Post date:** [June 9, 2017, 10:26am UTC](https://discourse.julialang.org/t/juno-and-interactive-plot/3989/20 "2017-06-09T10:26:28Z")

</div>

Hi,

I still did not find a way to plot in real time. Increasing the amount of data authorized does not work. I tried to find other solutions but I did not find any that would allow me to go on using jupiter notebook which is quite convenient.

Do you have any other idea to find a solution?

Thank you
