我的目標是讓 Jupyter 筆記本中的一個單元格顯示多個交互式小部件。具體來說,我想要四個滑塊來裁剪圖像,然后另一個單獨的滑塊來旋轉這個裁剪后的圖像。當然,當我運行代碼時,應該顯示兩個圖。這是我所擁有的。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,dinteractive_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_plotdef image_rot(i): img_rot=scipy.ndimage.rotate(frame_slic.T,i) plt.figure(figsize=(8,8)) plt.imshow(img_rot,cmap='RdBu') return iinteractive_plot_2 = interactive(image_rot, i = widgets.IntSlider(min=-180,max=180,step=1,value=0,description='Rotation'))我可以將它放在兩個單元格中(第一個單元格進行裁剪,第二個單元格旋轉),但不能放在一個單元格中。
1 回答

千萬里不及你
TA貢獻1784條經驗 獲得超9個贊
Jupyter 將只顯示一個小部件,因為它始終只顯示單元格中最后一個命令的輸出,因此您希望將兩個小部件放在一個命令中。您可以使用Layout來執行此操作,例如Box:
from ipywidgets import Box
items = [interactive_plot, interactive_plot_2]
box = Box(children=items)
box # <- this one command displays all children
添加回答
舉報
0/150
提交
取消