【问题标题】:Interactive jupyter plot using ipywidgets at its left side在左侧使用 ipywidgets 的交互式 jupyter 绘图
【发布时间】:2018-04-19 09:06:52
【问题描述】:

我有很多连接到图表的 ipywidgets 滑块,我希望将它们放在布局的左侧。除此之外,为了优化空间和提高可用性,输出图应位于右侧。

没有分层的结果如下图:

result without layering

你有什么办法让滑块在左边,输出在右边吗?

我已经尝试过使用交互式 HBox + VBox:

inter = wgt.interactive(f_arctan2,va=wgt.FloatSlider(min=-5.,max=5.,step=0.5,value=1.5),vb=wgt.FloatSlider(min=-6,max=6,step=0.5,value=0),
             va2= wgt.FloatSlider(min=-5.,max=5.,step=0.5,value=-1), vb2= wgt.FloatSlider(min=-5.,max=5.,step=0.5,value=-3) )

display(wgt.HBox(wgt.VBox(inter.children[:-1]),inter.children[-1]))

但是有一个元组错误

TypeError: init() 需要 1 到 2 个位置参数,但需要 3 个 给了

使用 inter.children.Output() 作为第二个参数也不起作用。

【问题讨论】:

  • 请添加一个完全可执行的代码示例

标签: python matplotlib jupyter-notebook ipywidgets sliders


【解决方案1】:

我发现的最佳解决方案是使用 HBox 和 VBox。

这是一个示例:

labels = Label(y= x_labels , x= [0,0,0,0,0], scales={'y': x_ord , 'x':  y_sc}, x_offset = -49, y_offset = 7,colors=['white','white','white', 'white','white'], default_size=24,  update_on_move=True)


histogram = Figure(marks=[bar,labels], axes=[ax_x,ax_y],  background_style = {'fill': 'White'},title=total, min_height = 50, title_style ={'font-size': '30px'})


ui = wgt.HBox([wgt.VBox([logo_w,company_w,model_w, aa_w, bb_w, ccc_w,avg_w,event_w]),histogram])

然后,我使用了交互式输出

def f_all(logo,company,...):
  ....code here...


out = wgt.interactive_output(f_all,{'logo':logo_w,'company': company_w, 'aa':aa_w, ...})

display(ui, out)

希望这对任何人都有帮助:-)

【讨论】:

    猜你喜欢
    • 2019-11-13
    • 2017-02-28
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多