我有一个dataframe
的坐标和时间戳,我试图将它们形象化为heatmap
,在这里我可以使用一个滑动条来调整时间,并且只选择与这个特定时间相关联的点。
为此,我使用Bokeh
创建一个小部件并输入variable H
,定义小时(0到23之间)。由于我在Bokeh
中找不到任何现成的工具,heatmaps
我构建了一个二维直方图并将其绘制为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)
欢迎任何提示!在
目前没有回答
相关问题 更多 >
编程相关推荐