IPython 未定义 jupyter lab 我的操作系统是 windows 10?

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

当我将 Jupyter Notebook 制作的笔记本放入 Jupyter Lab 中时,会出现以下消息: Javascript 错误:IPython 未定义。 我按照 Windows 10 页面上的说明安装了 jupyter lab,.......发生了什么事? 这是代码示例,这就是 jupyter 实验室中发生的情况:

%matplotlib notebook
import itertools
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation

def data_gen():
    for cnt in itertools.count():
        t = cnt / 10
        yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)

def init():
    ax.set_ylim(-1.1, 1.1)
    ax.set_xlim(0, 1)
    del xdata[:]
    del ydata[:]
    line.set_data(xdata, ydata)
    return line,

fig, ax = plt.subplots()
line, = ax.plot([], [], lw=2)
ax.grid()
xdata, ydata = [], []

def run(data):
    t, y = data
    xdata.append(t)
    ydata.append(y)
    xmin, xmax = ax.get_xlim()

    if t >= xmax:
        ax.set_xlim(xmin, 2*xmax)
        ax.figure.canvas.draw()
    line.set_data(xdata, ydata)

    return line,

ani = animation.FuncAnimation(fig, run, data_gen, interval=100, init_func=init,
                              save_count=100)
plt.show()
Javascript Error: IPython is not defined
C:\Users\marc_arias\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\animation.py:879: UserWarning: Animation was deleted without rendering anything. This is most likely not intended. To prevent deletion, assign the Animation to a variable, e.g. `anim`, that exists until you output the Animation using `plt.show()` or `anim.save()`.
  warnings.warn(
python windows jupyter
1个回答
0
投票

换线

%matplotlib notebook

%matplotlib widget

此行配置 matplotlib 使用哪个后端来渲染图表。

notebook
不适用于 Jupyter Notebook 7(或者我认为是 JupyterLab)。为此,您可能需要首先安装 ipympl

pip install ipympl

如果您不需要交互式图表,您也可以删除/注释掉该行。

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