bqplot填充线块工具提示

问题描述

我正在尝试绘制时间序列预测,并用阴影的不确定性间隔时间序列包围,并为不确定性的线和周长提供工具提示

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']],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对象,并将其作为填充对象,但是那也不起作用。谢谢!

解决方法

您会踢自己...对Figure调用中的标记重新排序,将不确定性放在第一位,然后将第二行放在第一位。列表的顺序类似于matplotlib中的zorder

example_fig = Figure(marks=[
    fcst_uncertainty,fcst_line,],axes=[x_ax_fcst,y_ax_fcst])

顺便说一句。