Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bokeh, zoom only on single axis, adjust another axis accordingly

How can one make bokeh use zoom only on one axis and automatically scale objects, so they take exactly the space given and add some padding on extreme points off zoom-able axis parallels, while rendering empty space out of scope?

In other words (or "madskills" to be exact): Example plot.

This is most widely used for stocks plotting, so consider I want to copy zoom behavior of https://www.tradingview.com/chart/?symbol=FX:XAUUSD with Bokeh. Thank you in advance.

like image 651
user8491711 Avatar asked Mar 08 '23 07:03

user8491711


2 Answers

Zoom on X axis only by using 'xwheel_zoom' tool:

from bokeh.plotting import figure
fig = figure(tools='xwheel_zoom', active_scroll='xwheel_zoom')

Auto-scale the other (Y) axis by invoking a custom JavaScript event whenever the first axis changes. In this event, you scan through the visible data and amend the axis range. Like in the following gist example: https://gist.github.com/kernc/719918ada11298168efd956afc1a04a8

like image 112
K3---rnc Avatar answered Mar 11 '23 05:03

K3---rnc


As of Bokeh 0.12.7 there is nothing built-in that will do this. Auto-ranging is always over the entire data set. There is no option to have auto ranging happen only over a subset of the data that is currently visible according to the extents of some other dimension.

It's possible to extend Bokeh, so it it conceivable that you could write a custom extension subclass of DataRange1d but it would not be a completely trivial matter:

http://docs.bokeh.org/en/latest/docs/user_guide/extensions.html

However, it seems like a reasonable feature request, so I'd encourage you to file a GitHub issue to discuss adding this capability directly to the core library:

https://github.com/bokeh/bokeh/issues

like image 27
bigreddot Avatar answered Mar 11 '23 04:03

bigreddot