1
JupyterノートブックでiPyWidgetsとMatplotlibを使用すると、複数のサブプロットを含むライブ更新図や複数のスライダを持つ複数の変数を取得するのはかなり簡単です。単純に2つのスライダー変数の有効プロット機能、およびコンストラクタを含むようにinteract
を設定します。Python:IpywidgetボタンからMatplotlibをリセットする
%pylab inline
from ipywidgets import *
from IPython.display import display
import numpy as np
import matplotlib
t = np.arange(0.0, 4*pi, 0.01)
def pltsin(f1, f2):
ax11 = plt.subplot(121)
ax11.set_title('Plot 1')
ax11.plot(t, sin(2*pi*t*f1/4/pi), 'k'); ax11.grid(True)
ax11.plot(t, cos(2*pi*t*f1/4/pi), 'r'); ax11.grid(True)
ax12 = plt.subplot(122)
ax12.set_title('Plot 2')
ax12.plot(t, sin(2*pi*t*f2/4/pi), 'k'); ax12.grid(True)
ax12.plot(t, cos(2*pi*t*f2/4/pi), 'r'); ax11.grid(True)
plt.show()
interact(pltsin, f1 = (1, 2, 0.01), f2 = (1, 2, 0.01))
これは、簡単にプロットに拡張することができ(例えば)3つのスライダはすべて1つのウィンドウで3つの多項式の係数を制御する(すなわち、サブプロットなし)。
しかし、すべての変数をデフォルトの状態に戻すリセットボタンがあると非常に便利です。どのようにしてipywidgetボタンのon_clickメソッドをスライダの変数やFigure自体に影響させることができますか?