位置为altair图例顶部中央。

7
我想把altair图例放在顶部中央。只需传递legend=alt.Legend(title=None, orient="top")即可将其移到顶部。我还了解到vega-lite中也可以这样做,但是我很难让它们同时起作用。
1个回答

11

Altair目前还不支持Vega-Lite的新版本中支持的"layout"属性,但是你可以使用另一个问题答案中提到的方法手动定位图例。

例如:

import altair as alt
from vega_datasets import data

source = data.cars()

alt.Chart(source).mark_circle(size=60).encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color=alt.Color('Origin', legend=alt.Legend(
        orient='none',
        legendX=130, legendY=-40,
        direction='horizontal',
        titleAnchor='middle'))
)

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接