2
votes

what is the easiest way to plot values from example for loop to same plot window? I try Plots, but atom doesn't open any plot windows. When I try to do same in Julia terminal everything is fine. Example:

using Plots
plot(Plots.fakedata(50,5),w=3)

I have socket connection from other program and I want to plot line of the values what I get. Or is this possible to do with PyPlot?

1
Try using the plotlyjs Plots backendspencerlyon2

1 Answers

5
votes

You need to use gui() to display the plot window.

In the REPL, objects that are returned are displayed. That's why anything without a ; gets displayed (also matrices, vectors, etc.). When you go to a script, that's no longer true (which is why you don't need to use ;). In Atom it's reading it in script mode, so you have to manually display things via display(obj), or if using plots you can just use gui().

To display things in the same plot window, you simply set reuse=true when setting the backend, i.e.

gr(reuse=true)

Note you can also add show=true to make it automatically show when plots are made instead of having to call gui().

Then to do live plotting, just push the new values into the plot. The full code looks like this:

using Plots
gr(reuse=true)
p =plot([0;.1],[0;.2])
gui()
for i=2:10
  push!(p,i*.1,randn())
  gui()
  sleep(.1) # To slow things down for show.
end

This answer should work with any backend. Note I switched to GR.jl since it tends to be faster