bokeh
bokeh copied to clipboard
[FEATURE] enable linebreaks in legend labels
Problem description
Sometimes I have legend labels which are very long and it would be nice to have the option to add a line break (to control the length of the entries). Because this is possible for other labels (thanks to this commit [#11578]) I hope this is also easy to enable for legends.
Example
from bokeh.plotting import figure, show, output_notebook
from bokeh.models import HoverTool
output_notebook()
p = figure(match_aspect=True, width=400, height=400)
# invisble rect to scale the y-axis as workaround
w_h = 2
p.rect(x=0, y=0, width=w_h, height=w_h, alpha=0)
p.wedge(
x=0,
y=0,
radius=1,
start_angle=0,
end_angle=3.1415,
color='blue',
legend_label="Short legend item",
)
p.wedge(
x=0,
y=0,
radius=1,
start_angle=3.1415,
end_angle=6.282,
legend_label="Long legend item\nLinebreaks would be nice.",
color='yellow',
)
show(p)
In this example you can see, that the second legend item is long and the \n
-newline character is replaced by a whitespace.
My wish is to start a new line without the box for the second part of the label.
This was supposed to be possible after PR #11949, but it needs a little more attention.
Hi! Thanks for you work @mattpap.
just to add to this (with bokeh==3.0.0.dev13):
p.legend.title='Long legend item\nLinebreaks would be nice.'
does also not line break. It just does a space. So I guess this may be so for all text around legends.