我正在开发基于 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/