bqplot 填充线块工具提示
bqplot filled Lines blocks tooltip
我正在尝试绘制时间序列预测,周围是带阴影的不确定性区间时间序列,并让工具提示适用于不确定性的线和周长。
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 对象并将其作为填充对象,但这也不起作用。谢谢!
你会踢自己的……重新排序 Figure
调用中的标记,将不确定性放在第一位,然后是行。列表的顺序类似于 matplotlib 中的 zorder
。
example_fig = Figure(marks=[
fcst_uncertainty,
fcst_line,
], axes=[x_ax_fcst, y_ax_fcst])
顺便说一句,很好的例子。
我正在尝试绘制时间序列预测,周围是带阴影的不确定性区间时间序列,并让工具提示适用于不确定性的线和周长。
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 对象并将其作为填充对象,但这也不起作用。谢谢!
你会踢自己的……重新排序 Figure
调用中的标记,将不确定性放在第一位,然后是行。列表的顺序类似于 matplotlib 中的 zorder
。
example_fig = Figure(marks=[
fcst_uncertainty,
fcst_line,
], axes=[x_ax_fcst, y_ax_fcst])
顺便说一句,很好的例子。