簡體   English   中英

散景堆疊酒吧-在酒吧旁邊添加文本標簽

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

我正在嘗試使用Bokeh 0.12.4創建一個堆積的酒吧。 我可以使用圖表界面創建條形圖。 但是,我在欄旁邊添加標簽有麻煩。

進一步來說:

  1. 有沒有一種方法可以使用bar()將標簽添加到每個條形? 我知道圖表界面有局限性。 如果沒有,如何使用繪圖界面創建堆疊的條形圖並在每個條形圖旁邊創建標簽?(我不希望標簽位於條形圖上,如您所見,如果在條形圖,所有文本將聚集在一起。)

  2. 如何將圖例移到條形圖區域之外? 因為它目前正在隱藏一些酒吧。

  3. 對於工具提示,我應該使用什么來顯示值? 現在我正在使用“ 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.charts API已被棄用和刪除,它是一個完整的死胡同。 Bokeh的最新版本在穩定且受支持的bokeh.plotting API中提供了更多更好的選擇。 在《用戶指南》部分的“ 處理分類數據 ”中,有堆疊和分組配置的許多帶有圖例和懸停工具提示的條形圖完整示例。

如果由於某種原因您不能更新到Bokeh的較新版本,我會建議您使用其他工具,而不是嘗試使bokeh.charts起作用。

如果可以更新,下面是一個完整的堆疊條形圖示例,其中帶有懸停工具和圖例之外的圖例,它們可與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