Is there a property to set the size of a legend? Right now my legends (irrespective the 'orient' placement) contain text labels that are cut-off.
Can you show an example?
Yes!
Altair code:
names = df_t['name'].unique().tolist()
scale = alt.Scale(domain=names, range=['#808080', '#FFD200'])
chart = alt.Chart(df_t).mark_bar().encode(
y=alt.Y('week:O'),
x=alt.X('amount:Q', scale=alt.Scale(domain=[0,40]) ),
color=alt.Color('name', legend=alt.Legend(title='Nname', orient = 'right'), scale=scale))
chart
Generated JSON:
{
"config": {"view": {"width": 400, "height": 300}},
"data": {
"values": [
{"name": "123456789 - Long name", "amount": 19, "week": "w0"},
{"name": "123456789 - Long name", "amount": 19, "week": "w1"},
{
"name": "123456789123456789123456789 - Even longer name",
"amount": 2,
"week": "w0"
},
{
"name": "123456789123456789123456789 - Even longer name",
"amount": 2,
"week": "w1"
},
{
"name": "123456789123456789123456789 - Even longer name",
"amount": 4,
"week": "w2"
},
{
"name": "123456789123456789123456789 - Even longer name",
"amount": 5,
"week": "w3"
}
]
},
"mark": "bar",
"encoding": {
"color": {
"type": "nominal",
"field": "name",
"legend": {"orient": "right", "title": "Nname"},
"scale": {
"domain": [
"123456789 - Long name",
"123456789123456789123456789 - Even longer name"
],
"range": ["#808080", "#FFD200"]
}
},
"x": {
"type": "quantitative",
"field": "amount",
"scale": {"domain": [0, 40]}
},
"y": {"type": "ordinal", "field": "week"}
},
"$schema": "https://vega.github.io/schema/vega-lite/v2.4.1.json"
}
Resulting graph:

Although this is a ridiculously long name, I would like to show it in full in the legend.
This is a good question for the vega-lite folks CC/ @domoritz @kanitw
You can set
"config": {
"legend": {
"labelLimit": 0
}
}
encode(
color=alt.Color('name',
legend=alt.Legend(title='Name', orient = 'right'),
scale=scale)
).configure_legend(labelLimit= 0)

Perfect, thanks!
Thanks!
You can set
"config": {
"legend": {
"labelLimit": 0
}
}
Thank You domoritz you saved me :)
Also worked for me. Thanks!
Most helpful comment
Perfect, thanks!