bqplot:ipython 个小部件未呈现

bqplot: ipython widgets not being rendered

我正在尝试使用 bqplot to plot some graphs in jupyter notebook along with some ipywidgets. I want to render the widgets horizontally adjacent to my plot as discussed in this issue,但我无法让小部件显示在我的 jupyter 笔记本中。

我的代码如下-

from bqplot import pyplot as plt
import ipywidgets as widgets
from pandas import DataFrame

class AdderDOEProblem_PlotUtils:
    def __init__(self, parseutils):
        self.data = DataFrame({'timestamps': parseutils.getTimestampValues(),
                            'Adder.sum': parseutils.getValues('Adder.sum'),
                            'Adder.a': parseutils.getValues('desvar_a.a'),
                            'Adder.b': parseutils.getValues('desvar_b.b')})
        # step size
        self.Adder_a__step = 0.1
        self.Adder_b__step = 0.1

        # axes configuration
        x_axis_values = self.data['Adder.a']
        y_axis_values = self.data['Adder.sum']

        self.fig = plt.figure(title='AdderDOEProblem')
        self.p = plt.plot(x_axis_values, y_axis_values)

        w_a_slider = widgets.FloatSlider(value=0, min=0, max=1, step=self.Adder_a__step, description='Adder.a')
        w_b_slider = widgets.FloatSlider(value=0, min=0, max=1, step=self.Adder_b__step, description='Adder.b')
        self.widgets_list = [w_a_slider, w_b_slider]

    def update (self, change):
        # Placeholder logic for testing 
        self.p.y = [i+1 for i in self.p.y]

    def plot (self):
        plt.show()
        for w in self.widgets_list:
            w.observe(self.update, 'value')
        self.update(None)
        widgets.HBox([widgets.VBox(self.widgets_list), self.fig])

当我在笔记本中 运行 时,我得到以下输出 -

我已经按照许多线程中的建议尝试了以下命令(但没有成功)-

jupyter nbextension enable --py widgetsnbextension

我错过了什么?

P.S。包的版本如下-
木星 - 1.0.0
ipython - 5.1.0
ipywidgets - 5.2.2
bqplot - 0.8.4

在您的绘图函数中,您必须 return 正在创建的 HBox。这就是它没有被显示的原因。显示的数字来自plt.show命令,它只显示当前上下文中的Figure。请注意,您不再需要 plt.show()。所以绘图函数看起来像,

def plot (self):
    for w in self.widgets_list:
        w.observe(self.update, 'value')
    self.update(None)
    return widgets.HBox([widgets.VBox(self.widgets_list), self.fig])