Number of Elements in the Legend of an Altair Chart

Viewed 526

I would like to control (ie. increase) the number of entries in the legend of an Altair chart but I can't figure out which property controls this behaviour.

By default, Altair charts list 30 elements in the legend. Any further entries get summarised as one line "...271 entries". Is it possible to display more (eg. 50) or fewer entries in the legend?

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')
).properties(
    width=300,
    height=300
)

enter image description here

1 Answers

The number of legend entries can be adjust by changing the symbolLimit property.

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(symbolLimit=10))
).properties(
    width=300,
    height=300
)

enter image description here

Related