gpt4 book ai didi

python - 如何并排比较两个交互式 Bokeh 图?

转载 作者:太空宇宙 更新时间:2023-11-03 19:59:15 31 4
gpt4 key购买 nike

我正在尝试将交互式 Bokeh map 与两位销售代表的销售额进行并排比较。我使用此代码两次更改第二张 map 的变量,然后使用 show(row(layout,layout2)),但图表是一个在另一个之上,而不是水平对齐。还有第一张 map 不更新值的问题。我想知道是否可以将下面的代码放入一个可能带有循环的数组中,而不是将代码复制两次。

from bokeh.io import curdoc, output_notebook
from bokeh.models import Slider, HoverTool
from bokeh.layouts import widgetbox, row, column

def json_data(selectedRep):
rep = selectedRep
df_rep = df[df['SalesRep'] == rep]
merged = map7.merge(df_rep, on='Name')
merged_json = json.loads(merged.to_json())
json_data = json.dumps(merged_json)
return json_data

geosource = GeoJSONDataSource(geojson=json_data('JIM'))

palette = brewer['YlGnBu'][9]

palette = palette[::-1]

color_mapper = LinearColorMapper(palette=palette, low = 50000, high = 400000)



hover = HoverTool(tooltips = [('Sales Region','@RegionName'),('Rank','@{Place Finished}'),('Sales Amt','@Sales')

color_bar = ColorBar(color_mapper = color_mapper, label_standoff =8, width = 500, height = 20, border_line_color=None,
location = (0,0), orientation ='horizontal')


p = figure(title = "JIM'S SALES TOTAL", plot_height = 500, plot_width = 500, toolbar_location = None, tools =[hover])
p.xaxis.major_tick_line_color = None # turn off x-axis major ticks
p.xaxis.minor_tick_line_color = None # turn off x-axis minor ticks

p.yaxis.major_tick_line_color = None # turn off y-axis major ticks
p.yaxis.minor_tick_line_color = None
p.xaxis.visible = False
p.xgrid.visible = False
p.yaxis.visible = False
p.ygrid.visible = False

p.patches('xs','ys', source = geosource,fill_color = {'field' :'Sales', 'transform' : color_mapper},
line_color = 'black', line_width = 0.25, fill_alpha = 1)
p.add_layout(color_bar, 'below')


def update_rep(attr, old, new):

rep = select.value
new_data = json_data(rep)
geosource.geojson = new_data
layout = column(p, widgetbox(select))
p.title.text = "%s 'S SALES TOTAL" %rep


select = Select(title='Which Rep', value='JIM', options=['ALLEN', 'CARL', 'MIKE', 'DAVID', 'JIM', 'LISA'])

select.on_change('value',update_rep)
layout = column(p, widgetbox(select))
curdoc().add_root(layout)

from bokeh.layouts import row
show(row(layout, layout2))

最佳答案

p = column(p, widgetbox(select))
p2 = column(p2, widgetbox(select2))
layout = row(p, p2)
d = curdoc().add_root(layout)

我找到了解决这两个问题的方法。

关于python - 如何并排比较两个交互式 Bokeh 图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59350440/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com