Search code examples
pythonlayoutbokeh

Possible to layout bokeh y-ticks inside plot


I've got a bunch of bokeh hbar plots in which the y-axis ticks are very long:

long y-tick labels

Some are even worse than this. Can I layout them inside the plot, or is there any other way in which to handle this?


Solution

  • Expanding on the comment to the question:

    from bokeh.io import show
    from bokeh.models import ColumnDataSource
    from bokeh.plotting import figure
    
    ds = ColumnDataSource(dict(x=[1, 2, 3],
                               y=['a', 'b', 'c']))
    p = figure(y_range=sorted(set(ds.data['y'])))
    p.hbar(y='y', height=0.8, left=0, right='x', source=ds)
    p.text(y='y', text='y', text_baseline='middle', x=0, x_offset=10, color='white', source=ds)
    show(p)