You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Altair分面布局异常求助:无法实现每行5个图表排列

问题分析与修正方案

你的代码存在参数使用错误:当你显式指定column='airline:N'来按列分面时,columns=5参数不会生效,这就导致所有分面图表被强制排成一行。

以下是两种可行的修正写法,都能实现每行显示5个小图表的布局:

方案一:使用facet参数配合columns控制行数

alt.Chart(df_airline_sentiment).mark_line().encode(
    x='date_flown:T',
    y='sentiment:Q',
).properties(
    width=200,
    height=200,
).facet(
    facet='airline:N',
    columns=5
)

方案二:在分面编码中使用wrap参数

alt.Chart(df_airline_sentiment).mark_line().encode(
    x='date_flown:T',
    y='sentiment:Q',
    facet=alt.Facet('airline:N', wrap=5)
).properties(
    width=200,
    height=200,
)

两种写法都会让分面图表自动按每行5个的规则排列,当航空公司数量超过5时,多余的图表会自动换行到下一行。

内容的提问来源于stack exchange,提问作者EverythingZen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 15:57:13