I wish to draw a bar plot using vbar method in Bokeh plotting, where x axis takes categorical values rather than numerical ones.
However, the example provided in the tutorial page (http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#) has only numerical x axis.
The bar plot must be updatable via widget and therefore it seems that Bar() cannot be used so instead I tried using vbar() method, where I can feed source data.
I found several similar questions and answers from the history, but still they don’t seem to exactly address the problem I have.
I tried the following code snippet but it failed with some errors:
from bokeh.plotting import figure, output_file
from bokeh.io import show
from bokeh.models import ColumnDataSource, ranges
from bokeh.plotting import figure
import pandas as pd
dat = pd.DataFrame([[‘A’,20],[‘B’,20],[‘C’,30]], columns=[‘category’,‘amount’])
source = ColumnDataSource(dict(x=,y=))
x_label = “Category”
y_label = “Amount”
title = “Test bar plot”
plot = figure(plot_width=600, plot_height=300,
x_axis_label = x_label,
y_axis_label = y_label,
source.data = dict(
x = dat.category,
y = dat.amount
plot.x_range = source.data[‘x’] # <===== ERROR
It seems to work if I specify x_range as the figure() argument, but what I want to do is to be able to update categorical values according to widget’s state, in which case, there must be some mechanism by which I can change the x_range on the fly.