使用 'density'、'aggregate' 和 'calculate' 转换的串联图表中的 Altair 间隔选择

Altair interval selection in concatenated charts with 'density', 'aggregate' and 'calculate' transforms

我在同一个 DF 上构建了两个串联的图表。左边是一个数据列的密度变换,右边是其他数据列聚合的散点图。

我想在左侧做一个间隔 selection 并相应地对右侧进行过滤器变换。不管我select,然而,右侧丢失所有数据点。

谁能看出我做错了什么?

import altair as alt
from vega_datasets import data
source = data.iris()

brush = alt.selection(type='interval', encodings=['x'])

PDFs = alt.Chart(source
).transform_density(
    'sepalWidth',
    as_=['size','density'],
    groupby=['species']
).mark_line().encode(
    x='size:Q',
    y='density:Q',
    color='species'
).add_selection(
    brush
)

Scatter = alt.Chart(source
).transform_aggregate(
    Frequency = 'count()',
    petalL_mean = 'mean(petalLength)',
    petalW_mean = 'mean(petalWidth)',
    sepalL_mean = 'mean(sepalLength)',
    groupby = ['species']
).transform_calculate(
    Value = 'datum.Frequency / (datum.petalL_mean * datum.petalW_mean)'
).mark_point().encode(
    x = 'sepalL_mean:Q',
    y = 'Value:Q',
    color='species'
).transform_filter(
    brush
)

PDFs | Scatter

Interval selection cannot be used for aggregate charts yet in Vega-Lite. The error behavior have been updated in a recent PR to Vega-Lite to show a helpful message.