我正在尝试绘制一个时间序列预测,周围有一个阴影的不确定性区间时间序列,并让工具提示既适用于线,也适用于不确定性的周边。
import pandas as pd
from bqplot import *
daterange = pd.date_range(start='2020-01-01', freq='1D', periods=20)
df = pd.DataFrame(index=daterange)
df['fcst'] = np.sin(np.arange(0,20)*2*np.pi / 20)
tt_ex = Tooltip(fields=['x', 'y' ], labels=['', ''], formats=["%B %Y", ',.2f'])
x_sc = DateScale()
y_sc = LinearScale()
fcst_vals = np.arange(0,20)*2*np.pi / 20
x_ax_fcst = Axis(scale=x_sc)
y_ax_fcst = Axis(scale=y_sc, orientation='vertical', tick_format='.2f')
fcst_uncertainty = Lines(x=[daterange.append(daterange[::-1])],
y=[((df['fcst']+0.2).append((df['fcst'][::-1]-0.2)))],
fill_colors=['blue'],
fill='inside',
marker = 'cross',
stroke_width=1,
close_path=True,
scales={'x': x_sc, 'y': y_sc},
tooltip=tt_ex)
fcst_uncertainty.fill_opacities = [0.2]
fcst_line = Lines(x=[daterange], y=[df['fcst']],
scales={'x': x_sc, 'y': y_sc},
marker='circle', colors=['blue'],
tooltip=tt_ex)
example_fig = Figure(marks=[
fcst_line,
fcst_uncertainty
], axes=[x_ax_fcst, y_ax_fcst])
display(example_fig)但是填充阻塞了填充区域内的主要时间序列的工具提示。有什么简单的方法可以解决这个问题吗?如果我移除填充,它会按预期工作。但我要的是满足感。我尝试在没有工具提示交互的情况下创建另一个Lines对象,并将其作为填充对象,但也不起作用。谢谢!
发布于 2020-10-06 16:13:01
您将在Figure调用中踢开yourself...reorder标记,以将不确定性放在第一位,将该行放在第二位。列表的顺序功能类似于matplotlib中的zorder。
example_fig = Figure(marks=[
fcst_uncertainty,
fcst_line,
], axes=[x_ax_fcst, y_ax_fcst])顺便说一下,这是一个很好的例子。
https://stackoverflow.com/questions/64217942
复制相似问题