在我的實現中,十字準線僅在懸停的情節中顯示。我目前正在使用 Bokeh 版本2.1.1和 Python Anaconda 版本3.7.6,使用 VSCode 版本 1.48 中的 Python 擴展。我不熟悉 Javascript,因此歡迎任何有助于調試我的代碼以正確顯示跨兩個圖的十字準線的幫助。我的代碼:# Importing libraries:import pandas as pdimport randomfrom datetime import datetime, timedeltafrom bokeh.models import CustomJS, CrosshairTool, ColumnDataSource, DatetimeTickFormatter, HoverToolfrom bokeh.layouts import gridplotfrom bokeh.plotting import figure, output_file, show# Function wrote by Hamid Fadishei to enable a linked crosshair within gridplot:def add_vlinked_crosshairs(figs):? ? js_leave = ''? ? js_move = 'if(cb_obj.x >= fig.x_range.start && cb_obj.x <= fig.x_range.end &&\n'? ? js_move += 'cb_obj.y >= fig.y_range.start && cb_obj.y <= fig.y_range.end){\n'? ? for i in range(len(figs)-1):? ? ? ? js_move += '\t\t\tother%d.spans.height.computed_location = cb_obj.sx\n' % i? ? js_move += '}else{\n'? ? for i in range(len(figs)-1):? ? ? ? js_move += '\t\t\tother%d.spans.height.computed_location = null\n' % i? ? ? ? js_leave += '\t\t\tother%d.spans.height.computed_location = null\n' % i? ? js_move += '}'? ? crosses = [CrosshairTool() for fig in figs]? ? for i, fig in enumerate(figs):? ? ? ? fig.add_tools(crosses[i])? ? ? ? args = {'fig': fig}? ? ? ? k = 0? ? ? ? for j in range(len(figs)):? ? ? ? ? ? if i != j:? ? ? ? ? ? ? ? args['other%d'%k] = crosses[j]? ? ? ? ? ? ? ? k += 1? ? ? ? fig.js_on_event('mousemove', CustomJS(args=args, code=js_move))? ? ? ? fig.js_on_event('mouseleave', CustomJS(args=args, code=js_leave))
無法將 Bokeh 中的 CrossHairTool 鏈接到多個圖
慕蓋茨4494581
2023-06-20 10:45:26