TLDR: I want to create an interactive visualization with Bokeh where I can toggle the appearance of individual bars in a bar plot based on the values of multiple categorical dataframe columns.
The data
I have a Pandas dataframe with 5 columns. One column contains sample ID numbers (x
), one column contains quantitative output data (y
), and the other three have categorical data used to classify each sample as big
or small
, A
or B
, and blue
or red
.
data = dict(size=['big', 'big', 'big', 'big', 'small', 'small', 'small', 'small'],
design=['A', 'A', 'B', 'B', 'A', 'A', 'B', 'B'],
color=['blue', 'red', 'blue', 'red', 'blue', 'red', 'blue', 'red'],
x=['1', '2', '3', '4', '5', '6', '7', '8'],
y=['10', '20', '10', '30', '10', '40', '10', '30'])
data = pd.DataFrame(data)
print(data)
Output:
size design color x y
0 big A blue 1 10
1 big A red 2 20
2 big B blue 3 10
3 big B red 4 30
4 small A blue 5 10
5 small A red 6 40
6 small B blue 7 10
7 small B red 8 30
The problem
I want to plot the above data as a bar graph, with the x
values plotted along the x axis, and the y
values plotted along the y axis.
I also want to toggle the appearance of the bars using something like Bokeh's CheckboxGroup, so that there is a total of 6 selectable checkboxes, one for each of the values in the three categorical columns (big
, small
, A
, B
, blue
, and red
). If all boxes are checked, all bars would be shown. If all but the A
boxes are checked, then only half the data is shown (only the half with design
value B
). If all but the A
and blue
boxes are checked, none of the data with design
value A
or color
value blue
will be shown in the bar plot.
The solution posted to this older StackOveflow question is close to what I want to achieve. However, unlike the dataframe described in the linked post, which only had 3 columns (an X column, a Y column, and a single categorical column which was tied to the Bokeh CheckboxGroup), I have 5 columns, 3 of which are categorical columns that I want tied to selectable checkboxes.
I am not very familiar with JavaScript, so I'm not sure how I could achieve what I am describing with Bokeh.