Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] enable linebreaks in legend labels #12331

Closed
mosc9575 opened this issue Aug 25, 2022 · 3 comments · Fixed by #12687
Closed

[FEATURE] enable linebreaks in legend labels #12331

mosc9575 opened this issue Aug 25, 2022 · 3 comments · Fixed by #12687

Comments

@mosc9575
Copy link
Contributor

mosc9575 commented Aug 25, 2022

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)

no legend line break

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.

@mattpap
Copy link
Contributor

mattpap commented Aug 25, 2022

This was supposed to be possible after PR #11949, but it needs a little more attention.

@broeder-j
Copy link

broeder-j commented Aug 26, 2022

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.

bokeh_plot_line_breaks

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants