【发布时间】:2018-01-03 10:29:43
【问题描述】:
我有以下数据,这些数据捕获了设备的当前类别以及类别更改是否受到影响。
Class Class_Change
S yes
S yes
G yes
P yes
P yes
V no
G yes
V no
V no
V yes
P no
现在我想在堆积条形图中显示每个类的是/否。像下面我在excel中创建的东西。该表是每个类的是/否计数,图表是它的堆积条形图。
我试过下面的代码:
df2 = pd.DataFrame({'count': df_class.groupby(["Class","Class_Change"]).size()}).reset_index()
class = df2['Class'].tolist()
class_change = df2['Class_Change'].tolist()
count = df2['count'].tolist()
source = ColumnDataSource(data=dict(Classes = class, count=count, ClassChange = class_change,color = Viridis5))
plot = figure(x_range=tiers ,y_range=(0,max(count)), plot_height=350, plot_width = 800,title="Counts",
toolbar_location=None, tools="")
labels = LabelSet(x = 'Class', y= 'count' , text='count', level='glyph',
y_offset=0 , source=source, render_mode='canvas')
plot.vbar_stack(class_change, x='class', width=0.9, color='color', source=source, legend=[value(x) for x in class_change])
但它给出了错误:
AttributeError: 'Figure' object has no attribute 'vbar_stack'
有人可以帮我解决这个问题吗?
【问题讨论】:
-
需要散景吗?
-
@COLDSPEED。是的!
标签: python bokeh stacked-chart