问题
I am trying to plot a function evolving in real time with Julia.
For that, I saw that GR package could be used in Julia, when I try to apply exactly the example given here :
import GR
GR.inline("mov")
x = [0:0.01:2*pi]
for i = 1:200
GR.plot(x, sin.(x + i / 10.0))
end
GR.show()
I get the following error message while executing the loop part :
expected Real or Complex
in #plot_args#12(::Symbol, ::Function, ::Tuple{Array{FloatRange{Float64},1},Array{Array{Float64,1},1}}) at /Users/myname/.julia/v0.5/GR/src/jlgr.jl:936 ....
I have looked a bit on internet and found this where someone seems to have a similar problem but I really dont understand the answers and what should I do to make it work.
I can also just find an other way to plot in real time (within a loop).
Can someone help with that please?
Thank you by advance
回答1:
Here is a solution that uses Plots to plot to GR. I am sure this can be done in GR directly as well, but not sure what is wrong with your example.
using Plots
gr(show = true) # in IJulia this would be: gr(show = :ijulia)
x = 0:0.01:2*pi
for i in 1:200
display(plot(x, sin.(x + i / 10.0)))
end
Note that this example is real-time (as per the question) and thus may lag a little. In the code in the example, a gif is created instead, which is then displayed to ijulia.
来源:https://stackoverflow.com/questions/44281135/real-time-plotting-with-julia