Jupyter播放小部件跳过步骤

问题描述 投票:0回答:1

更新:我已经简化了原来的问题了。

我想创建一个动画情节,但我的实现是跳帧。

x = np.arange(0,5,0.1)
y = np.cos(3*x)

def f(i):
    plt.plot(x[:i],y[:i]);
    plt.gca().axis([0,5,-1,1])
    plt.gca().set_title(f'{i}')

interactive(f, i=Play(value=0, min=0, max=50, step=1))

enter image description here

而不是我想要的步长(1),它每帧约5步。

行为发生在笔记本和jupyterlab,以及内联和笔记本前端(qazxsw poi)

matplotlib jupyter-notebook jupyter jupyter-lab ipywidgets
1个回答
0
投票

我认为这与执行绘图功能所花费的时间有关。尝试在绘图之间更改%matplotlib notebook,看起来这是以毫秒为单位指定的。

interval

%matplotlib inline import numpy as np import matplotlib.pyplot as plt from ipywidgets import * x = np.arange(0,5,0.1) y = np.cos(3*x) def f(i): plt.plot(x[:i],y[:i]); plt.gca().axis([0,5,-1,1]) plt.gca().set_title(f'{i}') interactive(f, i=Play(value=0, min=0, max=50, step=1, interval=500))

© www.soinside.com 2019 - 2024. All rights reserved.