real time plotting with Julia

我们两清 提交于 2019-12-14 01:17:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!