4

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.

user8491711
  • 81
  • 2
  • 9
  • Can you add some more explanation or examples of what you want? – clabe45 Aug 20 '17 at 18:55
  • Basically, the picture has it all: 1) When person uses zoomwheel, plot "stretches" on the x-axis, then looks up extreme y-points inside zoomed-in x-axis slice, scaling y-axis which makes the plot take the entire vertical space + adding some padding, so it would not look to nasty. This behavior is mostly used by stock chart, so look up https://www.tradingview.com/chart/?symbol=FX:XAUUSD , for example. – user8491711 Aug 20 '17 at 19:05

3 Answers3

7

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

K3---rnc
  • 6,717
  • 3
  • 31
  • 46
  • 1
    Updated version of the code on the gist here - https://stackoverflow.com/a/51227346/2801913. More similarites to the TradingView interface. – Graeme Jul 07 '18 at 22:25
1

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

bigreddot
  • 33,642
  • 5
  • 69
  • 122
  • Would I have any performance benefit for streaming bigdata if I do write such extension compared against d3js (or any other js plotting library, since I have rather superficial knowledge of js and its frameworks)? – user8491711 Aug 20 '17 at 19:37
  • I don't have the ability to say with any certainty. – bigreddot Aug 20 '17 at 20:01
0

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

alex.pilon
  • 512
  • 6
  • 18