如何通过使用HatchPattern用模式填充堆积的条形图

时间:2019-06-19 18:34:41

标签: python bokeh

我想在散景堆叠条形图中添加阴影填充图案,如此处针对基本条形所写: https://github.com/bokeh/bokeh/pull/8859

有没有人知道如何处理像这样的堆积条形物:

from bokeh.core.properties import value
from bokeh.io import show, output_file
from bokeh.plotting import figure

output_file("stacked.html")

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="")

p.vbar_stack(years, x='fruits', width=0.9, color=colors, source=data,
             legend=[value(x) for x in years])

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
p.legend.location = "top_left"
p.legend.orientation = "horizontal"

show(p)

1 个答案:

答案 0 :(得分:1)

对于内置模式,您只需将模式列表传递给vbar_stack,就和colors一样,这些值将在堆栈的所有级别上广播:< / p>

p.vbar_stack(..., hatch_pattern=['dot', 'spiral', 'vertical_wave'])

enter image description here