I am using Altair 4.1.0 to create interactive plots with 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. 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. Is there any way to do this in Altair?
alt.Chart.interactive
has bind_x
and bind_y
arguments which default to True
. If you set either of these to False
, that scale will not be part of the interaction:
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):
chart.add_selection(alt.selection_interval(bind='scales', encodings=['y']))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.