【问题标题】:How to animate a plot in python using the VisVis package?如何使用 VisVis 包在 python 中为绘图设置动画?
【发布时间】:2022-06-27 18:49:44
【问题描述】:

我正在尝试使用 visvis 为情节设置动画。

这是他们的示例代码:

import visvis as vv

# read image
ims = [vv.imread('astronaut.png')]

# make list of images: decrease red channel in subsequent images
for i in range(9):
    im = ims[i].copy()
    im[:,:,0] = im[:,:,0]*0.9
    ims.append(im)

# create figure, axes, and data container object
a = vv.gca()
m = vv.MotionDataContainer(a)

# create textures, loading them into opengl memory, and insert into container.
for im in ims:
    t = vv.imshow(im)
    t.parent = m

我补充说:

app = vv.use()
app.Run()

这行得通。但我需要动画情节,而不是图像,所以我尝试这样做:

import visvis as vv
from visvis.functions import getframe

# create figure, axes, and data container object
a = vv.gca()
m = vv.MotionDataContainer(a, interval=100)

for i in range(3):
    vv.plot([0, 2+i*10], [0, 2+i*10])
    f = getframe(a)
    t = vv.imshow(f)
    t.parent = m

a.SetLimits(rangeX=[-2, 25], rangeY=[-2, 25])
app = vv.use()
app.Run()

轴的初始化非常大,这就是我使用设置限制的原因,并且输出没有动画。我只得到最后一帧,所以从 (0,0) 到 (22, 22) 的一条线。

有人知道使用 visvis 的方法吗?

【问题讨论】:

    标签: python animation plot visualization


    【解决方案1】:

    事实证明,将框架添加为 MotionDataContainer 的子项并不是可行的方法。函数 vv.plot 返回 Line 类的一个实例,并且应该将该线添加为子项。如果有人遇到同样的问题,我可以写一个更详细的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      • 2020-10-18
      • 2022-11-07
      • 1970-01-01
      相关资源
      最近更新 更多