私は、垂直IntSliderの位置をmatplotlibの右側に変更する方法を検討しています。ここでは、コードは次のようになります。ipywidgetスライダのデフォルト位置をmatplotlib figureの側に変更する方法は?
from ipywidgets import interact, fixed, IntSlider
import numpy as np
from matplotlib import pyplot as plt
%matplotlib notebook
fig = plt.figure(figsize=(8,4))
xs = np.random.random_integers(0, 5000, 50)
ys = np.random.random_integers(0, 5000, 50)
ax = fig.add_subplot(111)
scat, = ax.plot(xs, ys, 'kx', markersize=1)
ax.grid(which='both', color='.25', lw=.1)
ax.set_aspect('equal'), ax.set_title('Rotate')
def rotate(theta, xs, ys):
new_xs = xs * np.cos(np.deg2rad(theta)) - ys * np.sin(np.deg2rad(theta))
new_xs -= new_xs.min()
new_ys = xs * np.sin(np.deg2rad(theta)) + ys * np.cos(np.deg2rad(theta))
new_ys -= new_ys.min()
return new_xs, new_ys
def update_plot(theta, xs, ys):
new_xs, new_ys = rotate(theta, xs, ys)
scat.set_xdata(new_xs), scat.set_ydata(new_ys)
ax.set_xlim(new_xs.min() - 500, new_xs.max() + 500)
ax.set_ylim(new_ys.min() - 500, new_ys.max() + 500)
w = interact(update_plot,
theta=IntSlider(min=-180, max=180, step=5,value=0, orientation='vertical'),
xs=fixed(xs),
ys=fixed(ys))
これは私が持っているものです。
これは私が欲しいものです:
に非常に単純な方法があるかもしれませんこれを行うが、私は自分自身を把握することはできません。
私はIPython.display
でVBox
を包む、その後VBox
にfig
とinteractive
ウィジェットの両方を配置しようとしましたが、それはうまくいきませんでした。
この例では、これに対するストレートな解決策が見つかりませんでした。
EDIT1:
ipywidgets出力領域を捕捉し、ウィジェット・コンテキスト内で使用Output()
クラスを提供します。
私はそれを使い方を理解しようとします。
これはオブジェクトです: https://github.com/jupyter-widgets/ipywidgets/blob/master/ipywidgets/widgets/widget_output.py
私の解決策を以下に試しましたか? –
はい、あなたは正しい道にいると思います。 update_plot関数からFigureとAxesの構築をアンラップして動作させる方法を見つけたら、私はあなたに答えます。 Output()オブジェクトを多く使用します。私はこれが私たちの問題を解決すると思います。 –