简体   繁体   English

朱莉娅与原子的生活情节

[英]Julia live plot with atom

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. 我尝试了Plots,但是atom没有打开任何绘图窗口。 When I try to do same in Julia terminal everything is fine. 当我尝试在Julia终端中执行相同操作时,一切都很好。 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? 或者这可能与PyPlot有关?

You need to use gui() to display the plot window. 您需要使用gui()来显示绘图窗口。

In the REPL, objects that are returned are displayed. 在REPL中,显示返回的对象。 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() . 在Atom中,它是以脚本模式读取的,因此您必须通过display(obj)手动显示内容,或者如果使用绘图,则只能使用gui()

To display things in the same plot window, you simply set reuse=true when setting the backend, ie 为了在同一个绘图窗口中显示内容,您只需在设置后端时简单地设置reuse = true,即

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() . 注意,您还可以添加show=true使其在绘制图时自动显示,而不必调用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 注意我切换到GR.jl,因为它倾向于更快

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM