自适应-通过选择小部件在bokeh中更新条形图时的自动缩放Y范围

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

我不确定我的问题是否是this question or this one的副本,但它们不具有可复制性和混乱性。

在散景中,当我使用select widget并更新绘图时,有可能更新x-y范围吗?

这在处理大小不同的数据时特别有用。

dictonary={'Station':['a','a','a','a','b','b','b','b','b'],'Passengers':[20,30,40,20,10000,15000,20000,8000,16000],'Date':[1,2,3,4,1,2,3,4,5]}
df=pd.DataFrame(dictonary)

source = ColumnDataSource(data=df)

def modify_doc(doc):
    station_list=['a','b']
    station_selected='a'
    df_r=df.copy()
    x_name='Date'
    y_name='Passengers'
    xrange=[0,df_r.Date.iloc[-1]]
    yrange=[0,df_r[y_name].max()]
    source = ColumnDataSource(data=df_r)
    hover=HoverTool(tooltips=[('Passengers','@Passengers'),('Station','@Station'),('Date','@Date')])
    plot=figure(title='Passengers for station',tools=[hover,'pan','wheel_zoom'], plot_width=400, plot_height=400,x_range=(xrange), y_range=(yrange))
    plot.vbar(x="Date", top="Passengers",source=source, width=1.5)
    def update_plot(attr, old, new):
        activity =  select.value
        data = df_r[df_r['Station'] == activity]
        source.data = ColumnDataSource(data=data).data


    select = Select(title='Select Station', value=station_selected, options=station_list)
    select.on_change('value', update_plot)

    layout=column(select, plot)
    doc.add_root(layout)
show(modify_doc)

这里是输出的屏幕截图:

Station 'a' before zooming

Station 'a' after zooming

Station 'b' before zooming

python data-visualization visualization bokeh
1个回答
1
投票

执行此操作时:

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