python - 在 Web App 中设置 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'] 
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)

结果是这样的:

Bokeh Layout with Line an Bar Cart next to each other

我正在寻找的是使它看起来像这样的方法:

Bokeh Layout with Bar Chart inside Line Chart

如何实现这个结果?

谢谢!

最佳答案

这是我想出的(适用于 Bokeh v1.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))

结果:

enter image description here

关于python - 在 Web App 中设置 Bokeh 图的绝对屏幕位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55276182/

相关文章:

python - Python 的数字字典

java - Getting WARN : SQL Error: 1205, SQLState : 41000 ERROR: Lock wait timeout exceeded; try restarting transaction. 使用hibernate保存记录

php - 使用 JS 或 PHP 进行 cometd 编程

javascript - 上传包含复数的 CSV 文件并在 Bokeh 网络应用程序中读取它

python - Bokeh 饼图显示百分比标签倒置

python - 将 django-rest-interface 与 http put 一起使用

python - 属性错误 : 'NoneType' object has no attribute 'strip'

php - 如何编码和存储动态权限约束?

python - Bokeh 服务器和 flask : get access to a bokeh attribute after submit

python - load_entry_point 看不到其他模块 - "No module named"错误