How to Expand All Legend Entries in Altair Plots

Viewed 522

Consider the following simple example:

import altair as alt
from vega_datasets import data

alt.Chart(data.cars.url).mark_point().encode(
    x='Horsepower:Q',
    y='Miles_per_Gallon:Q',
    color=alt.Color('Name:N', legend=alt.Legend(columns=8))
).properties(
    # Adjust chart width and height to match size of legend
    width=600,
    height=600
)

Outputs this chart chart_without_the_entries_expanded

What I would like to do is to expand those 271 entries.

I have been looking for this for a while now and not been able to found out how. Is this possible?

Thank you :)

1 Answers

You can specify the maximum number of legend symbols to display using symbolLimit, which defaults to 30. If set to zero, all symbols will be shown:

import altair as alt
from vega_datasets import data

alt.Chart(data.cars.url).mark_point().encode(
    x='Horsepower:Q',
    y='Miles_per_Gallon:Q',
    color=alt.Color('Name:N', legend=alt.Legend(columns=8, symbolLimit=0))
).properties(
    # Adjust chart width and height to match size of legend
    width=600,
    height=600
)

enter image description here

Related