私は最終的に@bigreddotの助けを借りてこれを理解しました。間違った物件を使っていたことが判明しました。 line_width
の代わりにwidth
を使用する必要がありました。 x_range
はdatetime
の範囲であり、datetimes
はミリ秒単位で表現されているため、正しく表示するには十分な幅が必要でした。これは、幅がx_axis
の特定の期間を表しているため、ズームインするときに比例幅を設定する処理です。
カラムをグループ化してColumnDataSource.data
を更新する方法のfreq
を変更する機能があるため、更新するときにwidth
を再計算する必要があります。
def get_data(freq='MS'):
return pd.DataFrame(srs.groupby(pd.Grouper(freq=freq)).mean())
source = ColumnDataSource(data=ColumnDataSource.from_df(get_data()))
def get_width():
mindate = min(source.data['date'])
maxdate = max(source.data['date'])
return 0.8 * (maxdate-mindate).total_seconds()*1000/len(source.data['date'])
f = figure(plot_width=550, plot_height=400, x_axis_type="datetime")
f.x_range.set(bounds='auto')
r = f.vbar(source=source, top='volume', x='date', width=get_width())
bar_glyph = f.renderers[-1].glyph
handle = show(f, notebook_handle=True)
と私の更新機能:
ここで作業コードです
def update_data(freq={'Quarter': 'QS', 'Month': 'MS', 'Week': 'W'}):
source.data = ColumnDataSource.from_df(get_data(freq))
r.glyph.width = get_width()
push_notebook()
i = interact(update_data)
は