如何为 Multifaceted Altair Graph 设置共享标题?

How do I set a shared title for a Multifaceted Altair Graph?

我想为我的多面 (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
    )

谢谢!

要为完整图表设置标题,您可以调整分面图表的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'
)