在散景图中过滤日期时间
Filter on datetime in Bokeh plot
我可以在 Bokeh 中对日期时间列进行过滤。
以下 code/plot 运行正常:
# imports
import pandas as pd
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, CDSView, GroupFilter
# dataframe and columndatasource
df = pd.DataFrame({'Date': list(pd.date_range(start='1/1/2018', end='1/03/2018')) * 3,
'Value': list(range(1, 10))})
source = ColumnDataSource(df)
剧情:
p = figure()
p.line(x='Date', y='Value', source=source)
show(p)
但是,我只想绘制日期为 1/3/2018
的行,而不创建新的 ColumnDataSource
。因此我使用 GroupFilter
和 CDSView
.
last_date = source.data['Date'].max() # select 1/3/2018
date_filter = GroupFilter(column_name='Date', group=str(last_date)) # create filter
view = CDSView(source=source, filters=[date_filter]) # create view
p = figure()
p.line(x='Date', y='Value', source=source, view=view) # use view
show(p)
但是这个图没有显示数据?关于如何过滤 Date
列的任何建议?
您遇到了这个问题:https://github.com/bokeh/bokeh/issues/7524
目前,GroupFilter
仅适用于字符串。
解决方法是创建任何其他类型的过滤器并自行过滤值。
我可以在 Bokeh 中对日期时间列进行过滤。
以下 code/plot 运行正常:
# imports
import pandas as pd
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, CDSView, GroupFilter
# dataframe and columndatasource
df = pd.DataFrame({'Date': list(pd.date_range(start='1/1/2018', end='1/03/2018')) * 3,
'Value': list(range(1, 10))})
source = ColumnDataSource(df)
剧情:
p = figure()
p.line(x='Date', y='Value', source=source)
show(p)
但是,我只想绘制日期为 1/3/2018
的行,而不创建新的 ColumnDataSource
。因此我使用 GroupFilter
和 CDSView
.
last_date = source.data['Date'].max() # select 1/3/2018
date_filter = GroupFilter(column_name='Date', group=str(last_date)) # create filter
view = CDSView(source=source, filters=[date_filter]) # create view
p = figure()
p.line(x='Date', y='Value', source=source, view=view) # use view
show(p)
但是这个图没有显示数据?关于如何过滤 Date
列的任何建议?
您遇到了这个问题:https://github.com/bokeh/bokeh/issues/7524
目前,GroupFilter
仅适用于字符串。
解决方法是创建任何其他类型的过滤器并自行过滤值。