有没有一种方法可以缩放然后进行选择间隔而无需使用 Altair 进一步缩放
Is there a way to zoom and then do a selection interval without further zooming with Altair
有一个散点图,我知道您在比例尺上使用绑定进行平移并使用滚轮进行缩放,这很棒。但是,一旦缩放,就需要一种方法来进行选择间隔,而无需进一步缩放效果。例如,需要一种通过 shift 键暂停或退出的方法。在 它使用鼠标事件。在 Altair 文档中根本没有关于如何执行此操作的示例。 API 在那里,但是 altair.EventType
不公开鼠标事件。
非常感谢如何让它在 Altair 中工作。
您可以在选择定义中使用事件修饰符来执行此操作(Altair 的文档中有一些示例 here)。
例如下面这张图表,不按住shift键时触发缩放动作,按住shift键时触发选择动作:
import altair as alt
from vega_datasets import data
source = data.cars()
zoom = alt.selection_interval(
bind='scales',
on="[mousedown[!event.shiftKey], mouseup] > mousemove",
translate="[mousedown[!event.shiftKey], mouseup] > mousemove!",
)
selection = alt.selection_interval(
on="[mousedown[event.shiftKey], mouseup] > mousemove",
translate="[mousedown[event.shiftKey], mouseup] > mousemove!",
)
alt.Chart(source).mark_circle(size=60).encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
).add_selection(zoom, selection)
可以在 vega 的 eventStream selector 文档中找到这些事件修饰符的语法。
有一个散点图,我知道您在比例尺上使用绑定进行平移并使用滚轮进行缩放,这很棒。但是,一旦缩放,就需要一种方法来进行选择间隔,而无需进一步缩放效果。例如,需要一种通过 shift 键暂停或退出的方法。在 altair.EventType
不公开鼠标事件。
非常感谢如何让它在 Altair 中工作。
您可以在选择定义中使用事件修饰符来执行此操作(Altair 的文档中有一些示例 here)。
例如下面这张图表,不按住shift键时触发缩放动作,按住shift键时触发选择动作:
import altair as alt
from vega_datasets import data
source = data.cars()
zoom = alt.selection_interval(
bind='scales',
on="[mousedown[!event.shiftKey], mouseup] > mousemove",
translate="[mousedown[!event.shiftKey], mouseup] > mousemove!",
)
selection = alt.selection_interval(
on="[mousedown[event.shiftKey], mouseup] > mousemove",
translate="[mousedown[event.shiftKey], mouseup] > mousemove!",
)
alt.Chart(source).mark_circle(size=60).encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
).add_selection(zoom, selection)
可以在 vega 的 eventStream selector 文档中找到这些事件修饰符的语法。