jupyter-notebook - 在 bqplot 中动态调整轴

标签 jupyter-notebook jupyter bqplot

我正在开发基于 jupyter 的仪表板进行数据分析,并计划使用 bqplot 绘制数据。仪表板的部分规范是能够调整轴以放大/缩小数据。到目前为止,我已经能够让它动态更新,而无需完全重新加载图形。有没有办法做到这一点?如果是这样,如何?以下是我大致意思的一个片段:

def updateXAxis(values):
    #Update X-axis min/max value here

x_sc = LinearScale(min=float(x_data[0]))
y_sc = LinearScale()

ax_x = Axis(label='X', scale=x_sc, grid_lines='solid', tick_format='0f')
ax_y = Axis(label='Y', scale=y_sc, orientation='vertical', tick_format='0.2f')

m_fig = dict(left=100, top=50, bottom=50, right=100)
fig = Figure(axes=[ax_x, ax_y], marks=data_values, fig_margin=m_fig)

x_range = IntRangeSlider(value=[0,1000],
                        min=0,
                        max=2000,
                        step=1,
                        description="X Axis",
                        disabled=False,
                        continuous_update=False,
                        orientation='horizontal',
                        readout=True)
interactive(updateXAxis, values=x_range)
fig

最佳答案

这里的问题最终是 interactive 功能不是很灵活。相反,应该使用 observe,下面是一个例子:

def updateXAxis(values):
    if change['type'] == 'change' and change['name'] == 'value':
        x_sc.min = change['new'][0]
        x_sc.max = change['new'][1]

x_sc = LinearScale(min=float(x_data[0]))
y_sc = LinearScale()

ax_x = Axis(label='X', scale=x_sc, grid_lines='solid', tick_format='0f')
ax_y = Axis(label='Y', scale=y_sc, orientation='vertical', tick_format='0.2f')

m_fig = dict(left=100, top=50, bottom=50, right=100)
fig = Figure(axes=[ax_x, ax_y], marks=data_values, fig_margin=m_fig)

x_range = IntRangeSlider(value=[0,1000],
                        min=0,
                        max=2000,
                        step=1,
                        description="X Axis",
                        disabled=False,
                        continuous_update=False,
                        orientation='horizontal',
                        readout=True)

x_range.observe(updateXAxis)
widgets.VBox([fig, x_range])

在我在这里提交的 git 问题中有一个稍微更详细的答案:https://github.com/bloomberg/bqplot/issues/712

关于jupyter-notebook - 在 bqplot 中动态调整轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52068011/

相关文章:

python - 删除 RISE 中的问号和进入/退出按钮(Jupyter Notebook)

jupyter 中的 r 图形 - 无法启动 png() 设备

python - 处理时的 Jupyter Notebook 计数器

适用于 Windows 的 Jupyter Notebook 上的 C++

visual-studio-code - vscode 中的 Jupyter - 转换为原始 NBCovert 或停用单元格?

python - 作为工具提示的容器不显示内容

python - 改变bqplot中Fig的大小?

python - 在以下路径中找不到名称为 'lab' 的模板子目录

python - ipywidgets,如何更改 slider 的值显示精度

python-3.x - jupyter 实验室中的 Bqplot 返回字符串而不是(交互式)图像