bqplot 채워진 선 블록 툴팁

Oct 06 2020

음영 처리 된 불확실성 간격 시계열로 둘러싸인 시계열 예측을 플로팅하고 불확실성의 선과 경계 모두에 대한 툴팁이 작동하도록하려고합니다.

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 개체를 만들고 채워진 개체로 만들려고 시도했지만 작동하지 않았습니다. 감사!

답변

2 ac24 Oct 06 2020 at 15:13

당신은 스스로를 차게 될 것입니다 ... Figure불확도를 먼저 배치하고 라인을 두 번째로 배치하기 위해 콜 마크를 재정렬하십시오 . 목록의 순서는 zordermatplotlib에서 와 유사하게 작동 합니다.

example_fig = Figure(marks=[
    fcst_uncertainty,
    fcst_line,

], axes=[x_ax_fcst, y_ax_fcst])

그건 그렇고 좋은 예입니다.