Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Altair – Remove ellipsis ("…") from legend with long strings

Via Python, I am using Altair to plot bar graphs. I was able to move the legend to be at the top, however, it is adding ellipsis (i.e. "…") at the end of each legend because my strings are too long. Is there any work around this? I tried gradientlength but it does not do the trick. Also, and as my strings are pretty long, would be possible to jump lines between each legend?

alt.Chart(df).mark_bar().encode(
    x=alt.X("fund:O", axis=alt.Axis(title=None, labels=False, ticks=False)),
    y=alt.Y("value:Q", axis=alt.Axis(title="Percentage", grid=True)),
    color=alt.Color("fund:N", legend=alt.Legend(orient="top")),
    tooltip=["data point info:O", "fund:N", "value", "bucket"],
    column=alt.Column(
        "bucket:N",
        header=alt.Header(title=None, labelOrient="bottom", labelAngle=x_angle),
        sort=list_to_sort,
        spacing=40,
    ),
).configure_view(stroke="transparent").interactive()

This is how it current looks like:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

One example of the legends is:

  • "Morningstar – FOUSA08OZU: Vanguard Total Bond Market II Index Fund Institutional Shares"

Documentation is here – https://altair-viz.github.io/user_guide/generated/core/altair.Legend.html

Similar ish question – Changing Size of Legend in Altair

>Solution :

If you want to show the full legend label instead of truncating it with ... you can set the labelLimit parameter to a higher number. You might also want to check out labelOverlap, labelPadding, and direction for the second part of your question regarding overlapping labels.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading