I have existing code that does some complex calculations in “real time”, and I’ve written it so that I can customize its output with user-defined callback functions. This works well for text output or network interfaces, but I cannot for the life of me get it to do anything useful for plotting. I’d like for it to produce a plot that gets extended and displayed as the calculation proceeds forward in time. But without calling gui(), no plot ever gets displayed on the screen. And when I do try to call gui() (or display(plt)), I get the cryptic message
ERROR: MethodError: no method matching getindex(::PyPlot.Figure, ::Symbol)
The applicable method may be too new: running in world age 21889, while current world is 21892.```
I’ve managed to reproduce this behavior with the following code:
using Plots
function myinit()
pyplot()
return plot()
end
function mycallback(p, t, x)
push!(p, [t,], [x,])
#display(p)
gui(p)
end
function calculate(t, fn1, fn2)
foo = fn2()
for i=1:size(t,1)
println(t[i], "\t", sin(t[i]))
fn1(foo, t[i], sin(t[i]))
end
end
function doall()
t=0:1:100
calculate(t, mycallback, myinit)
end