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