Juno and interactive plot

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

1 Like

This works fine for me (in Atom 1.17.2):

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

I’m on Plots and GR master.

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 :slight_smile:)

Oh, is it working on the plot pane?

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.

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

1 Like

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

@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:

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

but this one does

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.

You should use

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).

2 Likes

Excellent! Thank you.

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

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) :slight_smile:

1 Like

@jheinen

It works as well! Thank you a lot.

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

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.:

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

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 !

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

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

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

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:

jupyter notebook --NotebookApp.iopub_data_rate_limit=10000000

Seems to be a new feature in the notebook protocol. :slight_smile:

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

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