Updating a figures height to account for major label height

Hi,

I have a number of bar charts to plot and update with a Select widget.

For each plot, the length of the major x labels varies. With a horizontal label, the longer labels overlap so I rotate them 90 degs.

This has the negative effect of resizing the ‘plot area’ to compensate for the longer labels.

I would like to keep the ‘plot area’ the same with each selection so I have attempted to update the plot_height to compensate for the longer labels.

Unfortunately, this has no effect. Does anyone have any advice on how to achieve this? Is this a bug or a feature of plot_height?

Thanks,

Mike

The following code reproduces this problem:

from bokeh.plotting import figure, show, ColumnDataSource, curdoc

from bokeh.models.widgets import Select

from bokeh.layouts import layout

import numpy as np

x1 = [‘A’, ‘B’, ‘C’, ‘D’, ‘E’]

x2 = [‘A’ * 15, ‘B’ * 15, ‘C’ * 15, ‘D’ * 15, ‘E’ * 15]

xs = [x1, x2]

top1 = [0.1, 0.5, 0.6, 0.5, 0.3]

top2 = [0.5, 0.1, 0.6, 0.3, 0.2]

tops = [top1, top2]

source = ColumnDataSource(data=dict(x=x1, top=top1))

p = figure(x_range=x1, plot_height=500)

p.vbar(x=‘x’, top=‘top’, width=0.8, bottom=0, source=source)

p.xaxis.major_label_orientation = np.pi / 2

s = Select(title=‘select’, options=[‘0’, ‘1’])

def update():

newx = xs[int(s.value)]

newtop = tops[int(s.value)]

p.x_range.factors = newx

source.data = dict(x=newx, top=newtop)

label_height = max([len(i) for i in newx])

Try to adjust figure height

p.plot_height = 500 + label_height * 10

s.on_change(‘value’, lambda attr, old, new: update())

l = layout([[s, p]])

curdoc().add_root(l)