我想为我的多面 (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
提交
取消