如果可能的話,我想使用altair創(chuàng)建一個(gè)水平條形圖,其中包含水平連接并與條形對(duì)齊的表格中的一列或多列。我正在粘貼一個(gè)快速excel圖表的示例,以大致了解我想要什么。您網(wǎng)站上的以下示例(代碼和圖像),我為了空間而對(duì)其進(jìn)行了子集化,與我想要的類似。但是,與其使用與條形長(zhǎng)度對(duì)應(yīng)的值進(jìn)行文本疊加,不如創(chuàng)建一個(gè)具有值“x”的水平條形圖和一個(gè)與該示例相對(duì)應(yīng)的單獨(dú)值“p”的水平連接表。import altair as altfrom vega_datasets import datasource = 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)
1 回答

繁星點(diǎn)點(diǎn)滴滴
TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊
您可以使用水平串聯(lián)代替分層來實(shí)現(xiàn)此目的。例如:
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
添加回答
舉報(bào)
0/150
提交
取消