Python Altair-条形图-比例绑定

Python Altair-条形图-比例绑定,python,charts,scroll,scaling,altair,Python,Charts,Scroll,Scaling,Altair,我想结合Altair文档中的两个示例来获得垂直滚动条形图的能力。其中一个用例是甘特图 目前,我只能水平滚动,图表内容被压缩到我定义的高度属性: import altair as alt from vega_datasets import data source = data.wheat() bars = alt.Chart(source).mark_bar().encode( x='wheat:Q', y="year:O" ) text = bars.m

我想结合Altair文档中的两个示例来获得垂直滚动条形图的能力。其中一个用例是甘特图

目前,我只能水平滚动,图表内容被压缩到我定义的高度属性:

import altair as alt
from vega_datasets import data

source = data.wheat()

bars = alt.Chart(source).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'
)

selection = alt.selection_interval(bind='scales')
(bars + text).properties(height=300).add_selection(
    selection
)
如何配置图表以保持原始比例并允许在定义的高度内滚动


谢谢大家!

分类编码,例如序数(
“:O”
)和标称(
“:N”
)不能具有缩放范围选择。要使垂直轴具有交互性,应使y编码量化。例如:

bar=alt.Chart(源代码)。标记工具栏(orient='horizontal')。编码(
x='小麦:Q',
y='year:Q',
)

谢谢你,@jakevdp-关于这个主题的大多数答案都来自你,所以我为你的努力鼓掌!