user8491711
user8491711

Reputation: 91

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.

Upvotes: 5

Views: 6962

Answers (3)

alex.pilon
alex.pilon

Reputation: 522

FWIW Bokeh now has ywheel_zoom along with a number of other options introduced: https://github.com/bokeh/bokeh/pull/4841/files#diff-b846337d25cde71b26a5158abd54a002de416da396954ec636ff006a6d80da81R222

Upvotes: 0

bigreddot
bigreddot

Reputation: 34568

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

Upvotes: 1

K3---rnc
K3---rnc

Reputation: 7049

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

Upvotes: 7

Related Questions