VBar Shift "Anchor"

I want to shift vbars over a categorical x-axis…I’ve checked the documentation but can’t find anything, so hopefully the community can help me out.

I have a simple example:

source = ColumnDataSource(data=dict(
    x=['First', 'Second'],
    y=[10,5],
    align=['center', 'left']
))

I want to use this CDS to make two vbars.
I want the first vbar to align directly over the categorical x (“First”). This is the default way it’s rendered.
But I want the second vbar to align to the left, so instead of being directly over the categorical x, it’s to the left.
For text glyphs, there is the ‘anchor’ value we can adjust to physically shift a subset of the glyphs, but is there something for bars?

I was picturing something like the below:
p.vbar(x='x', bottom=0, top='y', align='align',source=source)

Categorical offsets are described in the documentation:

https://docs.bokeh.org/en/latest/docs/user_guide/topics/categorical.html#categorical-series-with-offsets

This could also be accomplished with dodge

https://docs.bokeh.org/en/latest/docs/user_guide/basic/bars.html#visual-offset

1 Like

Thank you, this is extremely helpful and just what I was looking for!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.