我正在尝试可视化与其路径相关的传感器输出。
我在一个图中将路径绘制为散点图,在第二个图中绘制一定范围的信号幅度。我需要可视化(突出显示)获取特定读数的路径点。
我开始使用散景作为后端,总的来说,我需要的可视化效果非常好。但我被困在这种特殊的互动上。
我想要一些标记,例如锚定在图形中间的垂直线。当我移动/滚动幅度图(底部)时,我想突出显示路径图上最接近标记线的读数的点。
示例代码:(
我想锚定标记线并在红点和垂直线之间添加交互,获取信号的索引,未实现。)
import numpy as np
import pandas as pd
from bokeh.io import output_file
from bokeh.models import ColumnDataSource, HoverTool, Span
from bokeh.plotting import figure, show
from bokeh.layouts import gridplot
output_file('interactive_path_sig.html', title="interactive path")
class InteractivePath():
def __init__(self):
x = np.arange(0, 1000, 0.5)
self.df = pd.DataFrame({"x": x,
"y": np.sin(x),
"z": np.cos(x)})
self.source = ColumnDataSource(self.df)
def plot_path(self):
plt = figure(title = "Sensor Path")
plt.scatter(x="x", y="y",source=self.source,
line_color=None, size = 6)
# TODO implement interaction instead of hard coded index
index=500 # this is where I think I need to create working callback
print("x={}, y={}".format(self.df['x'][index], self.df['y'][index]))
plt.circle(x=self.df['x'][index], y=self.df['y'][index],
fill_color="red", size=15)
hover = HoverTool()
hover.tooltips=[("index", "@index"), ("senosr","@z")]
plt.add_tools(hover)
return plt
def plot_signal(self):
plt = figure(x_range=(450, 550), title="Signal Amplitude")
plt.line(x="index", y="z", source=self.source, line_color="black", line_width=2)
# TODO implement interaction instead of hard coded index
index = 500 # I think this needs emit some singal to other plot
vline = Span(location=index, dimension='height', line_color='red', line_width=3)
plt.renderers.extend([vline])
return plt
GCT1015
相关分类