我想為我的多面 (2x2) Altair 圖表指定一個主標題。目前每個子圖上面都有標題,很亂。這是我正在使用的代碼: alt.data_transformers.disable_max_rows()selection = alt.selection_multi(fields=['component_name'], bind='legend')alt.Chart(top_n)\ .mark_line( strokeWidth = 1.2 ).encode( x = alt.X('click_date_local', title = 'Click Date', axis=alt.Axis(domain=False, format='%b%y', tickSize=0)), y = alt.Y('Num_Component_Visits', title = 'Component Clicks/Day'), color = alt.Color('component_name', scale=alt.Scale(scheme='tableau20'), legend=alt.Legend(title="Component Name")), opacity = alt.condition(selection, alt.value(1), alt.value(0.2)), tooltip = ['component_name'] ).properties( width=300, height=200, title = 'Clicks per Day for Top 15 Components by Covid Period' ).facet( column = alt.Column('covid_period', sort = ['Pre', 'Post'], title = 'Covid Period'), row = alt.Row('efficient_flag', title = 'Efficient Flag') ).resolve_scale( x='independent', y = 'independent' ).configure_axis( grid=False ).add_selection( selection )
1 回答

慕尼黑5688855
TA貢獻1848條經驗 獲得超2個贊
要設置完整圖表的標題,您可以調整title分面圖表的屬性。這有點令人困惑,因為title在圖表規范的許多地方都使用了它。下面是一個示例,希望可以使每個含義更加清晰:
import altair as alt
from vega_datasets import data
alt.Chart(data.iris()).mark_point().encode(
x=alt.X('petalLength:Q', title="X Title"),
y=alt.Y('petalWidth:Q', title="Y Title"),
color=alt.Color('species:N', title="Color Title")
).properties(
width=180,
height=180,
title='Chart Title'
).facet(
column=alt.Column('species:N', title='Column Title')
).properties(
title='Facet Title'
)
添加回答
舉報
0/150
提交
取消