Recreate seaborn boxplot with multiple categories with holoview of bokeh


I would like to create the boxplot from below figure with holoview or bokeh. Each category on the X-axis is split into different sub categories.
This plot is created with seaborn boxplot.

How can I achieve this with holoview boxwhisker by overlay? Or directly with Bokeh?
I cannot use the mulitple kdims with a boxwhisker because I would like to draw horizontal lines reflecting the upper spec limit, lower spec limit and the nominal. With holoview path I can draw those lines. But I don’t have mulitple kdims for the path. Combining the path with a multiple categorical boxwhisker gives errors.
Overlaying 2 boxplot plot them on top of each other. Is there an offset parameter for the X-axis?

Thanks in advance.

What I would do is create the “hard” part with hv.BoxWhisker then convert it to a Bokeh plot and add the limits

import holoviews as hv
import pandas as pd
from bokeh.models import Span
import panel as pn

df = pd.DataFrame([
    ['A', 1, 1.1],
    ['A', 1, 1.2],
    ['A', 1, 1.3],
    ['A', 1, 1.2],
    ['A', 2, 2.2],
    ['A', 2, 1.2],
    ['A', 2, 3.2],
    ['A', 2, 4.2],
    ['B', 1, 1.6],
    ['B', 1, 1.7],
    ['B', 1, 1.8],
    ['B', 1, 1.7],
    ['B', 2, 3.2],
    ['B', 2, 5.2],
    ['B', 2, 4.2],
    ['B', 2, 2.2],
], columns=['group','col','val'])

# Create boxplot
box = hv.BoxWhisker(df, ["group", "col"], "val")
box = box.opts(show_grid=True, box_fill_color=hv.dim('col').str(), cmap="Set1", height=500, width=500, show_legend=False) 

# Convert to bokeh figure and add hline
figure = hv.render(box) 
hline = Span(location=5, dimension='width', line_color='red', line_width=3)

# Just to show in Jupyter

That is an interesting approach. I need to study it.

I use the path instead of the span, because the limits can differ from category to category. In 1 plot they doesn’t need to be the same.

1 Like