
I am using the hack here to relocate my Legend outside the plot area. However, this “squashes” the plot area horizontally, which I don’t want. I need to increase the width of the figure:
the_figure.width += legend_width
But how to get legend_width? At the moment I’m doing the following horrible kludge to sum up the pixel widths of all the graphic elements that make up the Legend. This is especially irksome for the text labels, which look they are being rendered in a variable-width font, which looks OK so I don’t mind, but:
leg = the_figure.legend[0]
all_label_len = [ len(x.label['value']) for x in leg.items ]
max_label_len = max ( all_label_len )
label_font_size = leg.label_text_font_size
# It's a string like '13px` so need to int-ify it:
label_font_size = int(label_font_size[:-2])
max_label_width = max_label_len * label_font_size
# Here it comes ... ugh
legend_width = 2 * ( leg.border_line_width + leg.margin + leg.padding) + leg.glyph_width + max_label_width
This is clumsy and fragile, so surely there must be a better way! I’ve scoured the docs and there doesn’t appear to be any attribute of a Legend object that corresponds to what I want. Please can someone help?


