[英]Bokeh Horizontal Stacked Bar Chart
I am trying to convert my vertical stacked bar chart to a horizontal stacked bar chart, but I can not get the rotation to happen. 我正在尝试将垂直堆叠的条形图转换为水平堆叠的条形图,但是无法进行旋转。 I tried using hbar to create the rotation, but the chart still ends up staying in place. 我尝试使用hbar创建轮换,但图表仍然最终停留在原处。 All tips appreciated! 所有提示表示赞赏!
from bokeh.charts import Bar, output_file, show, hplot
from bokeh.models import HoverTool, ColumnDataSource, Range1d, LabelSet, Label
# create data
data = {
'customer': ['Cust 1', 'Cust 2', 'Cust 1', 'Cust 3', 'Cust 1', 'Cust 2'],
'itemSold': ['python', 'python', 'pypy', 'pypy', 'jython', 'jython'],
'sales': [200, 600, 850, 620, 400, 550]
}
#create hover tooltip
hover = HoverTool(tooltips=[
("sales", "$sales"),
("customer", "@customer"),
("itemSold", "@itemSold")
])
# x-axis itemSold , stacking customer
bar = Bar(data, values='sales', label='itemSold', stack='customer',
title="Python itemSold Sampling", legend='top_right', sizing_mode = "scale_both", tools=[hover, 'wheel_zoom'])
bar.hbar(y = data['sales'], height=0.5, right = data['customer'])
output_file("stacked.html")
show(bar)
bokeh.charts seems to have been deprecated in 0.12.9 so I've done it with the latest (0.12.16 as of writing), hopefully you're in a position where you can upgrade without any problems, should be backwards compatible pretty far back though. bokeh.charts在0.12.9中似乎已被弃用,因此我已使用最新版本(在撰写本文时为0.12.16)完成该操作,希望您可以在没有任何问题的情况下进行升级,应该向后兼容虽然很远。
Also I hope the stack is the right way round! 我也希望筹码是正确的方法! This example may also help. 这个例子也可能有帮助。
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.io import show, output_file
# create data
products = ['python', 'pypy', 'jython']
customers = ['Cust 1', 'Cust 2']
colours = ['red', 'blue']
data = {
'products': products,
'Cust 1': [200, 850, 400],
'Cust 2': [600, 620, 550]
}
source = ColumnDataSource(data)
p = figure(y_range=products)
p.hbar_stack(customers, y='products', height=0.5, source=source, color=colours)
show(p)
output_file("stacked.html")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.