StormsEdge
StormsEdge

Reputation: 885

Bokeh VBar chart data not populating

I am looking to create a VBar chart with a select widget in Bokeh. Prior to adding the Select widget I am just trying to populate a VBar with a single tech firm. When I execute the below code, I get the figure output as expected with the correct title and axis titles and colors etc, but there is no data populated. What am I missing?

#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)

Example Data in one_name:

Mock Data

print(one_name.dtypes)

yields PROFIT = int64, Company Name = object, QTR = object

Upvotes: 0

Views: 302

Answers (1)

bigreddot
bigreddot

Reputation: 34568

When using categorical values on axes, you have to inform Bokeh what the values are, and what order you want them to appear in on the axis (it has no way to guess your intentions). Typically, something like:

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

Passing that as x_range will sort the unique QTR values lexicographically on the x-axis, but you can put them in whatever order you need.

Upvotes: 1

Related Questions