我想在 IPython (python3) 中使用Matplotlib和ipywidgets实现交互式绘图。那么,我怎样才能有效地做到这一点(毫不拖延地顺利改变)?
另一个问题是为什么这段代码有效?!
from ipywidgets import *
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x = np.linspace(0, 2 * np.pi)
def update(w = 1.0):
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(x, np.sin(w * x))
fig.canvas.draw()
interact(update);
但是,这不起作用?!
from ipywidgets import *
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
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);