如何并排比较两个交互式散景图?

问题描述 投票:1回答:1

我正在尝试将交互式散景图与两个销售代表的销售情况进行比较。我使用此代码两次更改了第二个地图的变量,然后使用了show(row(layout,layout2)),但是这些图形彼此叠置而不是水平对齐。还存在第一个映射不更新值的问题。我想知道是否可以将下面的代码放入可能带有循环的数组中,而不是将代码重复两次。

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))
python bokeh geopandas
1个回答
0
投票
p = column(p, widgetbox(select))
p2 = column(p2, widgetbox(select2))
layout = row(p, p2)
d = curdoc().add_root(layout)

我想出了两个问题的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.