简体   繁体   English

使用交互式 plot 在 Altair 中仅缩放一个轴

[英]Scale only one axis in Altair with interactive plot

I am using Altair 4.1.0 to create interactive plots with Python.我正在使用 Altair 4.1.0 创建带有 Python 的交互式绘图。 I want to be able to zoom in some part of my chart by scaling only one axis, for example only the y-axis while keeping the x-axis fixed.我希望能够通过仅缩放一个轴来放大图表的某些部分,例如仅缩放 y 轴,同时保持 x 轴固定。 From the documentation I could not find a way to do this.从文档中我找不到这样做的方法。 My understanding is that alt.interactive() corresponds to .add_selection(alt.selection_interval(bind='scales')) , but still I don't see how to achieve my purpose.我的理解是alt.interactive()对应于.add_selection(alt.selection_interval(bind='scales')) ,但我仍然看不到如何达到我的目的。 Is there any way to do this in Altair?有没有办法在 Altair 中做到这一点?

alt.Chart.interactive has bind_x and bind_y arguments which default to True . alt.Chart.interactivebind_xbind_y arguments 默认为True If you set either of these to False , that scale will not be part of the interaction:如果您将其中任何一个设置为False ,则该比例将不会成为交互的一部分:

chart.interactive(bind_x=False)

Alternatively, you can do this manually by specifying the encodings you want bound ( ['x'] , ['y'] , or ['x', 'y'] , which is the default):或者,您可以通过指定要绑定的编码( ['x']['y']['x', 'y'] ,这是默认值)手动执行此操作:

chart.add_selection(alt.selection_interval(bind='scales', encodings=['y']))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM