我正在使用Bokeh服务器设计一个Bokeh布局。我正在定义两个主要列(见附件图像),并试图链接右侧列上所有绘图的x轴。问题是:
因此,我想知道,一旦定义了列中的所有图(即下面plotDataset的输出),是否可以事后设置链接行为。我的直觉是遍历对象,获取子对象,并将x_range设置为第一个绘图,但我不知道如何做到这一点。
下面是我正在努力实现的一个简化版本。理想情况下,我会得到x_range的第一个绘图的fCol,并将其应用于所有其他绘图就在return column(fCol)之前
任何想法都是非常感谢的!而且,我是Python的初学者,所以如果你看到其他可怕的东西,请大声喊一声!
谢谢
def plotTS(data, col):
tTmp = []
# A loop that defines each tab of the plot
for i in range(len(col)):
fTmp = figure()
fTmp.circle(data[:]['time'], data[:][col[i]], color=color)
# Append tab
tTmp.append(Panel(child=fTmp))
# Return the tabs
return Tabs(tabs=tTmp)
def plotDataset(data):
col = ['NDVI', 'EVI'] # Name of the tabs
fCol = []
fCol.append(plotTS(data, col))
# NOTE: I use an append approach because in reality plotTS is called more than once
return column(fCol)
# General layout - I did not include the code for the left column
layout = row(leftColumn, plotDataset(data))发布于 2019-05-17 14:19:26
请参阅下面的代码(Bokeh v1.1.0)。
from bokeh.models import Panel, Tabs, Column, Row
from bokeh.plotting import figure
from tornado.ioloop import IOLoop
from bokeh.server.server import Server
from bokeh.application import Application
from bokeh.application.handlers.function import FunctionHandler
def modify_doc(doc):
leftColumn = Column(figure())
def plotTS(data, col):
tTmp = []
for i in col:
fTmp = figure()
fTmp.circle(data['x'], data['y'], color='black')
tTmp.append(Panel(child=fTmp, title = i))
return Tabs(tabs=tTmp)
def plotDataset(data):
col = ['NDVI', 'EVI']
fCol = plotTS(data, col)
shared_range = None
for panel in fCol.tabs:
fig = panel.child
if shared_range is None:
shared_range = fig.x_range
else:
fig.x_range = shared_range
return Column(fCol)
layout = Row(leftColumn, plotDataset(data = dict(x = [1, 2, 3], y = [1, 2, 3])))
doc.add_root(layout)
io_loop = IOLoop.current()
server = Server(applications = {'/app': Application(FunctionHandler(modify_doc))}, io_loop = io_loop, port = 5002)
server.start()
server.show('/app')
io_loop.start() https://stackoverflow.com/questions/56163824
复制相似问题