Altair 生成水平连接的水平条形图 table

Altair to generate horizontal bar chart with horizontally concatenated table

如果可能,我想使用 altair 创建一个水平条形图,其中包含来自 table 的一列或多列水平连接并与条形对齐。我正在粘贴一个快速 excel 图表的示例,以大致了解我想要什么。

以下来自您网站的示例(代码和图像),我为了 space 而对其进行了子集化,与我想要的相似。但是,我想创建一个值 "x" 的水平条形图和一个水平连接的 table 和一个单独的值 "p",对应于该样本。

import altair as alt
from vega_datasets import data

source = data.wheat()
sourceTrunc = source.head(15)

bars = alt.Chart(sourceTrunc).mark_bar().encode(
    x='wheat:Q',
    y="year:O"
)

text = bars.mark_text(
    align='left',
    baseline='middle',
    dx=3  # Nudges text to right so it doesn't appear on top of the bar
).encode(
    text='wheat:Q'
)

(bars + text).properties(height=400)

您可以使用 horizontal concatenation 代替分层来实现此目的。例如:

import altair as alt
from vega_datasets import data

source = data.wheat()
sourceTrunc = source.head(15)

bars = alt.Chart(sourceTrunc).mark_bar().encode(
    x='wheat:Q',
    y="year:O"
)

text = alt.Chart(sourceTrunc).mark_text().encode(
    y=alt.Y('year:O', axis=None),
    text='wheat:Q'
).properties(width=30)

bars | text