如何展开 Altair 图中的所有图例条目

Ali*_*a V 3 python legend altair

考虑以下简单示例:

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
)

Run Code Online (Sandbox Code Playgroud)

输出此图表Chart_without_the_entries_expanded 图表

我想做的是扩展这 271 个条目

我已经寻找这个有一段时间了,但无法找到方法。这可能吗?

谢谢 :)

jak*_*vdp 7

您可以使用 指定要显示的图例符号的最大数量symbolLimit,默认为 30。如果设置为零,则将显示所有符号:

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
)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述