【问题标题】:bqplot filled Lines blocks tooltipbqplot 填充线条块工具提示
【发布时间】:2020-10-06 00:52:56
【问题描述】:

我正在尝试绘制一个时间序列预测,周围是阴影的不确定区间时间序列,并且工具提示适用于不确定性的线和周长。

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

【问题讨论】:

    标签: python jupyter-notebook ipywidgets bqplot


    【解决方案1】:

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

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

    顺便说一句,很好的例子。

    【讨论】:

    • 谢谢!你踢自己是对的。您可以从我按顺序定义对象的事实中看到我的蠕虫小大脑正在寻找答案(我确实想到了zorder),但不知何故我并没有将它们与@987654325 关联起来@ 按此顺序。
    猜你喜欢
    • 2020-04-13
    • 2010-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多