朱莉娅实时绘图 [英] real time plotting with Julia
问题描述
我正在尝试绘制一个随Julia实时变化的函数.
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 :
预期实数或复数
/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).
有人可以帮忙吗?
先谢谢您
推荐答案
这里是一种使用图"绘制到GR的解决方案.我确信这也可以直接在GR中完成,但不确定您的示例出了什么问题.
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
请注意,此示例是实时的(根据问题),因此可能会有些滞后.在示例代码中,创建了一个gif,然后将其显示给ijulia.
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.
这篇关于朱莉娅实时绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!