如何通过python bokeh中的单个选择小部件控制堆叠的条形数量

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

我已使用以下代码在输入数据集df上使用python bokeh创建了垂直堆积的条形图,]

print(df.head())

  YearMonth         A         B         C         D         E
0    Jan'18  1587.816  1586.544   856.000  1136.464  1615.360
1    Feb'18  2083.024  1847.808  1036.000  1284.016  2037.872
2    Mar'18  2193.420  1850.524  1180.000  1376.028  2076.464
3    Apr'18  2083.812  1811.636  1192.028  1412.028  2104.588
4    May'18  2379.976  2091.536  1452.000  1464.432  2400.876

堆积的条形图代码-

from bokeh.plotting import figure
from bokeh.models import Axis
from bokeh.models import LabelSet, ColumnDataSource
chart_colors = ['#7b68ee', '#9acd32', '#e244db',
                '#d8e244', '#FF0000', '#eeeeee', '#56e244', 'black']

source=ColumnDataSource(df)

yearmonth=df['YearMonth'].unique().tolist()

p = figure(x_range=yearmonth, plot_height=400,plot_width=1000, title="Stacked Bar Chart")

segment=['A','B','C','D','E']
colors= chart_colors[:len(segment)]
r1=p.vbar_stack(segment, x='YearMonth', width=0.5,color=colors, source=source)
legend = Legend(items=[(YM, [r]) for (YM, r) in zip(segment, r1)], location=(0, 30))
p.add_layout(legend, 'right')
show(p)

现在,我想通过使用小部件(最好是单个选择小部件)来限制段(即堆叠的条)的数量。谁能指导我如何使用bokeh服务功能。我不想使用Javascript回调功能。

我已使用以下代码在输入数据集df上使用python bokeh创建了垂直堆叠的条形图-print(df.head())YearMonth A B C D E 0 ...

python-3.x widget visualization bokeh
1个回答
0
投票

这将需要一些非凡的工作才能实现。 vbar_stack方法是一种便利函数,实际上创建了多个字形渲染器

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