Python 在Web应用程序中设置Bokeh图表的绝对屏幕位置
我试图设置Bokeh图表在布局中的绝对位置,以便其中一个图显示在另一个图的顶部。现在当我在策划这样的事情时:Python 在Web应用程序中设置Bokeh图表的绝对屏幕位置,python,web-applications,bokeh,Python,Web Applications,Bokeh,我试图设置Bokeh图表在布局中的绝对位置,以便其中一个图显示在另一个图的顶部。现在当我在策划这样的事情时: from bokeh.io import curdoc from bokeh.plotting import figure from bokeh.layouts import layout import numpy as np x = np.arange(1,10.1,0.1) y = [i**2 for i in x] categories = ['A', 'B'] va
from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.layouts import layout
import numpy as np
x = np.arange(1,10.1,0.1)
y = [i**2 for i in x]
categories = ['A', 'B']
values = [1000, 1500]
fig1 = figure(width=600,plot_height=600, title="First Plot")
fig1.line(x=x, y=y)
fig2 = figure(width=200,plot_height=250,x_range=categories,
title="Second Plot") fig2.vbar(x=categories, top=values, width=0.2)
l = layout([[fig1,fig2]])
curdoc().add_root(l)
结果将是:
我正在寻找的是某种使它看起来像这样的方法:
这一结果如何实现
谢谢大家! 这就是我的想法(适用于BokehV1.0.4)。您需要将鼠标移到绘图上,以使另一个跳转到绘图中,但您也可以从回调中复制JS代码,并手动将其添加到Bokeh生成的HTML中,从而获得相同的结果
from bokeh.plotting import figure, show
from bokeh.layouts import Row
from bokeh.models import ColumnDataSource, CDSView, BooleanFilter, CustomJS, BoxSelectTool, HoverTool
import pandas as pd
plot = figure(tools = 'hover', tooltips = [("x", "@x"), ("y", "@y")])
circles = plot.circle('x', 'y', size = 20, source = ColumnDataSource({'x': [1, 2, 3], 'y':[1, 2, 3]}))
inner_plot = figure(name = 'inner_plot', plot_width = 200, plot_height = 200)
lines = inner_plot.line('x', 'y', source = ColumnDataSource({'x': [8, 9, 10], 'y':[8, 6, 8]}))
code = """ div = document.getElementsByClassName('bk-root')[0];
tooltip_plot = div.children[0].children[1]
tooltip_plot.style = "position:absolute; left: 340px; top: 350px;"; """
callback = CustomJS(code = code)
plot.js_on_event('mousemove', callback)
show(Row(plot, inner_plot))
结果: