如何在 Jupyter notebook 的同一个单元格中包含多个交互式小部件
How to include multiple interactive widgets in the same cell in Jupyter notebook
我的目标是让 Jupyter notebook 中的一个单元格显示多个交互式小部件。具体来说,我希望有四个滑块用于裁剪图像,然后有另一个单独的滑块用于旋转裁剪后的图像。当然,当我 运行 代码时,这两个图都应该显示。这是我的。
def image_crop(a,b,c,d):
img_slic=frame[a:b,c:d]
plt.figure(figsize=(8,8))
plt.imshow(img_slic,cmap='RdBu')
return a,b,c,d
interactive_plot = interactive(image_crop, a = widgets.IntSlider(min=0,max=2000,step=10,value=500,description='Vertical_Uppper'),
b = widgets.IntSlider(min=0,max=2000,step=10,value=500,description='Vertical_Lower'),
c = widgets.IntSlider(min=0,max=1000,step=10,value=500,description='Horizontal_Left'),
d = widgets.IntSlider(min=0,max=1000,step=10,value=500,description='Horizontal_Right') )
interactive_plot
def image_rot(i):
img_rot=scipy.ndimage.rotate(frame_slic.T,i)
plt.figure(figsize=(8,8))
plt.imshow(img_rot,cmap='RdBu')
return i
interactive_plot_2 = interactive(image_rot, i =
widgets.IntSlider(min=-180,max=180,step=1,value=0,description='Rotation'))
我可以在两个单元格中使用它(第一个单元格裁剪,第二个单元格旋转),但不能在一个单元格中使用。
我的目标是让 Jupyter notebook 中的一个单元格显示多个交互式小部件。具体来说,我希望有四个滑块用于裁剪图像,然后有另一个单独的滑块用于旋转裁剪后的图像。当然,当我 运行 代码时,这两个图都应该显示。这是我的。
def image_crop(a,b,c,d):
img_slic=frame[a:b,c:d]
plt.figure(figsize=(8,8))
plt.imshow(img_slic,cmap='RdBu')
return a,b,c,d
interactive_plot = interactive(image_crop, a = widgets.IntSlider(min=0,max=2000,step=10,value=500,description='Vertical_Uppper'),
b = widgets.IntSlider(min=0,max=2000,step=10,value=500,description='Vertical_Lower'),
c = widgets.IntSlider(min=0,max=1000,step=10,value=500,description='Horizontal_Left'),
d = widgets.IntSlider(min=0,max=1000,step=10,value=500,description='Horizontal_Right') )
interactive_plot
def image_rot(i):
img_rot=scipy.ndimage.rotate(frame_slic.T,i)
plt.figure(figsize=(8,8))
plt.imshow(img_rot,cmap='RdBu')
return i
interactive_plot_2 = interactive(image_rot, i =
widgets.IntSlider(min=-180,max=180,step=1,value=0,description='Rotation'))
我可以在两个单元格中使用它(第一个单元格裁剪,第二个单元格旋转),但不能在一个单元格中使用。