【问题标题】:Jupyter Play widget skipping stepsJupyter Play 小部件跳过步骤
【发布时间】:2019-02-11 05:15:30
【问题描述】:

更新:我已经简化了我最初的问题。

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

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))

而不是我想要的步长 (1),它以每帧大约 5 步的速度播放。

这种行为发生在 notebook 和 jupyterlab 以及 inline 和 notebook 前端 (%matplotlib notebook)

【问题讨论】:

  • 您能否举一个您的代码示例,其中包含一些随机数据作为输入?
  • 请注意,没有minimal reproducible example,任何人都无法复制此内容。
  • 我添加了一个简单的例子和​​一个 gif @ac24

标签: matplotlib jupyter-notebook jupyter jupyter-lab ipywidgets


【解决方案1】:

我认为这与执行绘图功能所需的时间有关。尝试在绘图之间更改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))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-08
    相关资源
    最近更新 更多