散景VBar图表数据未填充

时间:2018-06-20 18:11:30

标签: python pandas jupyter-notebook bokeh

我正在寻找使用Bokeh中的选择小部件创建VBar图表的方法。在添加“选择”小部件之前,我只是想用一个技术公司来填充VBar。当我执行以下代码时,我得到了带有正确标题和轴标题以及颜色等的图形输出,但是没有填充数据。我想念什么?

#Hist
b_hist = figure(title="Tech Data", 
                tools=["save, wheel_zoom,box_zoom,reset"], 
                background_fill_color = "white")
#title formatting
b_hist.title.align = "center"
b_hist.title.text_color = "midnightblue"
b_hist.title.text_font_size = '18pt'

#axis title formatting
b_hist.yaxis.axis_label = "Millions"
b_hist.xaxis.axis_label = "Quarters"
b_hist.xaxis.axis_label_text_color = "midnightblue"
b_hist.yaxis.axis_label_text_color = "midnightblue"
b_hist.xaxis.axis_label_text_font_size = '14pt'
b_hist.yaxis.axis_label_text_font_size = '14pt'

one_name = tech_firms[tech_firms['Company Name']=="Apple"]

b_hist.vbar(x = one_name.QTR, top = one_name.PROFIT, width=0.9)

show(b_hist)

one_name中的示例数据:

Mock Data

print(one_name.dtypes)

收益PROFIT = int64, Company Name = object, QTR = object

1 个答案:

答案 0 :(得分:0)

在轴上使用分类值时,必须告知Bokeh这些值是什么,以及它们在轴上出现的顺序(无法猜测您的意图)。通常情况如下:

p = figure(..., x_range=sorted(df.QTR.unique())

将其传递为x_range会按字典顺序在x轴上对唯一的QTR值进行排序,但是您可以按照需要的顺序将其放置。