平行坐标图#

平行坐标图是一种可视化图表,它通过为每个独立的数据点绘制一条单独的线来展示数据。在 Altair 中,可以通过先将数据转换为合适的表示形式来创建此类图表。此示例展示了使用 Iris 数据集的平行坐标图。

import altair as alt
from vega_datasets import data

source = data.iris()

alt.Chart(source, width=500).transform_window(
    index='count()'
).transform_fold(
    ['petalLength', 'petalWidth', 'sepalLength', 'sepalWidth']
).mark_line().encode(
    x='key:N',
    y='value:Q',
    color='species:N',
    detail='index:N',
    opacity=alt.value(0.5)
)
import altair as alt
from vega_datasets import data

source = data.iris()

alt.Chart(source).transform_window(
    index='count()'
).transform_fold(
    ['petalLength', 'petalWidth', 'sepalLength', 'sepalWidth']
).mark_line().encode(
    x='key:N',
    y='value:Q',
    color='species:N',
    detail='index:N',
    opacity=alt.value(0.5)
).properties(width=500)