How do I link the CrossHairTool in bokeh over several plots?

后端 未结 5 1275
逝去的感伤
逝去的感伤 2020-12-30 07:34

When moving the crosshair (dimensions=width) in one plot I want to see the same position in the other plot(s). My plots share the same x-axis.

Here is the plot setup

5条回答
  •  没有蜡笔的小新
    2020-12-30 08:06

    As of bokeh v2.2.1 the solution is simplified. I am not sure whether it was already possible like this in previous versions. Here an example for sharing crosshair for both dimensions between 9 plots in a gridplot in bokeh v2.2.1:

    import numpy as np
    from bokeh.plotting import figure, show
    from bokeh.layouts import gridplot
    from bokeh.models import CrosshairTool
    
    plots = [figure() for i in range(6)]
    [plot.line(np.arange(10), np.random.random(10)) for plot in plots]
    crosshair = CrosshairTool(dimensions="both")
    for plot in plots:
        plot.add_tools(crosshair)
    
    show(gridplot(children=[plot for plot in plots], ncols=3))
    

提交回复
热议问题