使用matplotlib和ipywidget的交互式图 [英] Interactive Graph with matplotlib and ipywidget

查看:114
本文介绍了使用matplotlib和ipywidget的交互式图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试跟进已讨论但尚未完全解决的问题,在这里:

解决方案

  • 当在jupyter笔记本中未启用javascript小部件时会发生这种情况.

  • 激活您安装了jupyter笔记本电脑的环境.

  • 运行此命令:

    • jupyter nbextension enable --py --sys-prefix小部件nbextension
  • 您将获得类似以下内容的输出:

启用笔记本扩展jupyter-js-widgets/extension ...-验证:确定

  • 此外,请不要忘记在运行此命令后重新启动笔记本电脑.

I am trying to follow up on a problem discussed, but not completely solved, here: Interactive matplotlib using ipywidgets

I am using Python 2.7 in a jupyter notebook environment and want the following function to be modified interactively in jupyter.

%matplotlib notebook
from ipywidgets import *
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2 * np.pi)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
line, = ax.plot(x, np.sin(x))

def update(w = 1.0):
    line.set_ydata(np.sin(w * x))
    fig.canvas.draw()

interact(update);

While the slider shows and can be modified, no graph is shown.

Where is my misunderstanding?

[EDIT] Works well now with the solution below, result:

解决方案

  • it happens when javascript widget is not enabled in the jupyter notebook.

  • activate the environment where you have installed jupyter notebook.

  • run this command:

    • jupyter nbextension enable --py --sys-prefix widgetsnbextension
  • you will get an output something like this:

Enabling notebook extension jupyter-js-widgets/extension... - Validating: OK

  • also, don't forget to restart the notebook after running this command.

这篇关于使用matplotlib和ipywidget的交互式图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆