简体   繁体   中英

Is there a bug in bokeh's stacked bar chart or is it just me?

I am creating a stacked bar chart using Bokeh, where I am struggling with the coloring. The best way to communicate my issue is probably by showing my result: bar chart with wrong use of color in the fourth bar

In words: the color that I defined as the color for my category 'status 8' (dark green) is being used as some kind of frame on top of the fourth bar. This is quite confusing for the reader as it leads to the conclusion that there are issues in that component which are part of 'status 8' - even though there are not, and that is why I would like to fix this and get rid of the "frame".

This is the code with which I created the plot:

from bokeh.plotting import figure
from bokeh.palettes import RdYlGn8
from bokeh.io import show
import math

components = ['1.1 Component 1', '1.2 Component 2', '3.1 Component 3', '4.5 Component 4']
status = ['status 1', 'status 2', 'status 3', 'status 4', 'status 5', 'status 6', 'status 7', 'status 8']

csd = {'components': ['1.1 Component 1', '1.2 Component 2', '3.1 Component 3', '4.5 Component 4'],
        'status 1': [0, 4, 12, 1],
        'status 2': [0, 0, 10, 1],
        'status 3': [0, 0, 5, 0],
        'status 4': [0, 3, 17, 0],
        'status 5': [0, 2, 36, 0],
        'status 6': [0, 0, 1, 0],
        'status 7': [0, 20, 0, 0],
        'status 8': [5, 26, 24, 0]}

colors = RdYlGn8[::-1]

plot = figure(x_range=components, plot_height=600, plot_width=1400, title="Issues per Component",
              toolbar_location=None, tools="hover", tooltips="$name: @$name")

plot.vbar_stack(status, x='components', width=0.9, color=colors, source=csd, legend_label=status)
plot.y_range.start = 0
plot.legend.location = "top_left"
plot.legend.orientation = "horizontal"
plot.x_range.range_padding = 0.1
plot.xaxis.major_label_orientation = math.pi / 4

show(plot)

By the way, I also tried defining the colors manually, as tuples and lists (eg ('#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850') ). This did not work either.

That is the outline of the (zero-height) bar. If you don't want the outlines drawn you will have to set line_color to None.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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