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

繁星點點滴滴
TA貢獻1803條經驗 獲得超3個贊
您可以使用水平串聯代替分層來實現此目的。例如:
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
添加回答
舉報
0/150
提交
取消