简体   繁体   中英

How to Expand All Legend Entries in Altair Plots

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 chartchart_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:)

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
)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM