为散景vbar

时间:2017-10-30 12:15:19

标签: pandas bokeh

我正在制作带散景的条形图。为此,我将一些值组合在一起。这些值是对问卷的回答(1-非常好到7-非常差)。有时,没有人回答“非常好”。在我的条形图中,我想为没有给出答案的人提供空条。我怎么做?我认为这将是x_range参数,但如果我指定它,我的情节是空的。我的代码如下所示:

df[answer] = df[answer].astype(str)
group = df.groupby(answer)
source = ColumnDataSource(group)
# with x_range=group, I get a graph, but without empty bars
p = figure(plot_height=350, x_range=[0, 7])
p.vbar(x=answer, top='SurveyId_count', width=0.9, source=source)
p.y_range.start = 0
save(p)

我也尝试了x_range =(1,7)等,但它没有产生我想要的结果。

1 个答案:

答案 0 :(得分:0)

Categorical factors are strings. Additionally, when making a categorical range you must supply all the factors, explicitly, yourself. By coincidence your factors happen to look similar to a range of numbers, but in general categorical factors are actually arbitrary names, there is no way for Bokeh to know what they are unless you tell it.

Since you haven't provided a complete example that can be run, it's not possible for me to provide an answer that is actually tested, but you probably want something like:

x_range = [str(x) for x in range(1,8)] 
相关问题