我有dataframe
坐标和时间戳,我正在尝试将它们显示为heatmap
,我可以使用滑动条来调整时间并仅选择链接到的点这个特定时刻。
为此,我使用Bokeh
创建窗口小部件并输入variable H
,定义小时(介于0和23之间)。由于我在heatmaps
中找不到Bokeh
的任何开箱即用工具,我构建了一个2D直方图,并将其绘制为Bokeh
图像。
但遗憾的是,滑块在播放时没有更新数据......有什么想法,为什么它不起作用?
x=itineraries['Itinerary Longitude Point A']
y=itineraries['Itinerary Latitude Point A']
a=itineraries['Itinerary Longitude Point A']
b=itineraries['Itinerary Latitude Point A']
z=itineraries['Itinerary Created Hour of Day']
source = ColumnDataSource(data=dict(x=x, y=y,z=z,a=a, b=b, p=p))
original_source = ColumnDataSource(data=dict(x=a, y=b,z=z))
plot = figure(y_range=(-24, -23), x_range=(-47, -46))
C, xedges, yedges = np.histogram2d(source.to_df()['y'], source.to_df()['x'], bins=75, range=[[-24,-23], [-47,-46]], normed = True)
X, Y = np.meshgrid(xedges, yedges)
plot.image(image = [C], x=-47, y=-24, dw=1, dh=1,
palette=['#f7fbff',
'#deebf7',
'#c6dbef',
'#9ecae1',
'#6baed6',
'#4292c6',
'#2171b5',
'#FFFFFF'])
callback = CustomJS(args=dict(source=source), code="""
var data = source.data;
var H = cb_obj.value;
x = data['x']
y = data['y']
z = data['z']
a = data['a']
b = data['b']
for (i = 0; i < x.length; i++)
{
if (z[i]==H)
{
x[i]=a[i]
y[i]=b[i]
}
else
{
x[i]=-23
y[i]=-47
}
}
source.change.emit();
""")
hour_slider = Slider(start=0, end=23, value=12, step=1, title="Hour of day")
hour_slider.js_on_change('value', callback)
layout = row(
plot,
widgetbox(hour_slider),
)
output_file("slider.html", title="slider.py example")
show(layout)
欢迎任何提示!