如何展开 Altair 图中的所有图例条目
How to Expand All Legend Entries in Altair Plots
考虑以下简单示例:
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
)
输出此图表
我想做的是扩展这 271 个条目。
我已经找了一段时间了,一直没找到。这可能吗?
谢谢:)
您可以使用 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
)
考虑以下简单示例:
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
)
输出此图表
我想做的是扩展这 271 个条目。
我已经找了一段时间了,一直没找到。这可能吗?
谢谢:)
您可以使用 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
)