简体   繁体   English

散景堆叠酒吧-在酒吧旁边添加文本标签

[英]Bokeh Stacked Bar- adding text label next to the bar

I am trying to create a stacked bar using Bokeh 0.12.4. 我正在尝试使用Bokeh 0.12.4创建一个堆积的酒吧。 I am able to create the bar using the chart interface. 我可以使用图表界面创建条形图。 However, I have trouble adding the label next to the bar. 但是,我在栏旁边添加标签有麻烦。

More specifically: 进一步来说:

  1. Is there a way that I can add the label to each bar using bar()? 有没有一种方法可以使用bar()将标签添加到每个条形? I know the chart interface has limitations. 我知道图表界面有局限性。 If not, how do I create stacked bar chart using plotting interface and create labels next to each bar?(I don't want the label to be on the bar, as you can see, some of the sections are really small, if on the bar, all the text will be clustered together.) 如果没有,如何使用绘图界面创建堆叠的条形图并在每个条形图旁边创建标签?(我不希望标签位于条形图上,如您所见,如果在条形图,所有文本将聚集在一起。)

  2. How do I move the legend outside the bar chart area? 如何将图例移到条形图区域之外? Because it is hiding some of the bar currently. 因为它目前正在隐藏一些酒吧。

  3. For the tooltip, what should I use to show the value? 对于工具提示,我应该使用什么来显示值? Right now I am using "y" but the value is not correct. 现在我正在使用“ y”,但该值不正确。

     df = pd.DataFrame(tb, columns=['Files Due', 'Files Past Due', 'Files WIP', 'No Errors', 'Errors Explained', 'Files Failed - Pending Resolution', 'date']) bar = Bar(df, values=blend('Files Due', 'Files Past Due', 'Files WIP', 'No Errors', 'Errors Explained', 'Files Failed - Pending Resolution', name='Number of Files', labels_name='KPI'), label=cat(columns='date', sort=False), stack=cat(columns='KPI', sort=False), color=color(columns='KPI', palette=['#BE4248', '#21374B', '#D7DADB', '#586473', '#E7DACB','#4A89AA'], sort=False), legend='top_right', tooltips=[('Status', '@KPI'),('Number of Files', '@y')], bar_width=0.2, ylabel='KPI') js5, div5 = components(bar) 

Bokeh stacked bar chart 散景堆积条形图

The bokeh.charts API has been deprecated and removed, it is a complete dead-end. bokeh.charts API已被弃用和删除,它是一个完整的死胡同。 The latest versions of Bokeh offer more and much better options in the stable and supported bokeh.plotting API. Bokeh的最新版本在稳定且受支持的bokeh.plotting API中提供了更多更好的选择。 There are many complete examples of bar charts with legends and hover tools tips, in stacked and grouped configurations in the User's Guide section Handling Categorical Data . 在《用户指南》部分的“ 处理分类数据 ”中,有堆叠和分组配置的许多带有图例和悬停工具提示的条形图完整示例。

If you cannot update to a newer version of Bokeh for some reason, I would go so far as to suggest finding a different tool to use, rather than trying to make bokeh.charts work. 如果由于某种原因您不能更新到Bokeh的较新版本,我会建议您使用其他工具,而不是尝试使bokeh.charts起作用。

If you can update, here is a complete example of stacked bar chart with hover tool and legend outside the plot that will work with Bokeh 0.13.0 : 如果可以更新,下面是一个完整的堆叠条形图示例,其中带有悬停工具和图例之外的图例,它们可与Bokeh 0.13.0

from bokeh.io import show
from bokeh.models import Legend
from bokeh.plotting import figure

fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
years = ["2015", "2016", "2017"]
colors = ["#c9d9d3", "#718dbf", "#e84d60"]

data = {'fruits' : fruits,
        '2015'   : [2, 1, 4, 3, 2, 4],
        '2016'   : [5, 3, 4, 2, 4, 6],
        '2017'   : [3, 2, 4, 4, 5, 3]}

p = figure(x_range=fruits, plot_height=250, title="Fruit Counts by Year",
           toolbar_location=None, tools="hover", tooltips="$name @fruits: @$name")

rs = p.vbar_stack(years, x='fruits', width=0.9, color=colors, source=data)

p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xgrid.grid_line_color = None
p.axis.minor_tick_line_color = None
p.outline_line_color = None

legend = Legend(items=[(fruit, [r]) for (fruit, r) in zip(fruits, rs)], location=(0, 30))
p.add_layout(legend, 'right')

show(p)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM