Julia - 使用PyPlot实时变化热图

时间:2015-11-22 13:08:18

标签: matplotlib julia heatmap

我正在朱莉亚进行模拟,我需要一个实时变化的热图。我正在使用PyPlot,并尝试将此answer用于julia

date -Ins --date='10 weeks ago'

代码运行但imshow没有更新,我想这是因为无法像在python中那样设置图像对象的数组。怎么会在朱莉娅这样做呢?我可以通过每次迭代调用imshow来实现它,但是对于较大的循环,这会变得很慢。

1 个答案:

答案 0 :(得分:0)

Julia v0.5 rc3PyPlot v"2.2.1+"上,上述代码在REPL上运行,也可以在非交互模式下运行,如julia plot.jl,< / p>

julia> using PyPlot
julia> using PyPlot
julia> ion()
julia> fig = figure()
PyObject <matplotlib.figure.Figure object at 0x3280c5f50>
julia> ax = fig[:add_subplot](111)
PyObject <matplotlib.axes._subplots.AxesSubplot object at 0x328242410>
julia> img = ax[:imshow](rand(50,50))
PyObject <matplotlib.image.AxesImage object at 0x31f337710>
julia> show()
julia> # draw some data in loop
   for i in 1:10
       # wait for a second
       sleep(1)
       # replace the image contents
       img[:set_array](rand(50,50))
       # redraw the figure
       fig[:canvas][:draw]
   end

这导致绘图随时间间隔变化1秒。