Bokeh, two y axes, disable one axis for zooming / panning

similar to matplotlib command ax.set_navigate(False)?

Below is a minimal example of using an ipython laptop.

from bokeh.plotting import figure
from bokeh.models import LinearAxis, Range1d
from bokeh.io import output_notebook, show
output_notebook()

s1=figure(width=250, plot_height=250, title=None, tools="pan, wheel_zoom")
s1.line([1, 2, 3], [300, 300, 400], color="navy", alpha=0.5)
s1.extra_y_ranges = {"foo": Range1d(start=1, end=9)}
s1.add_layout(LinearAxis(y_range_name="foo"), 'right')
s1.line([1, 2, 3], [4, 4, 1], color="firebrick", alpha=0.5, y_range_name="foo")
show(s1)

Is it possible to hold the second y axis in place when zooming and panning on another y axis?
Using the PanTool options did not help me with this problem.

Edit: Screenshot inserted:

Screenshothot actual output
The blue line is drawn on the first axis, the red on the second

If I zoom in, move around the x axis, I want the red line to stay in place.

+5
source share
2 answers

callback y JavaScript, , :

from bokeh.plotting import figure
from bokeh.models import LinearAxis, Range1d, CustomJS
from bokeh.io import output_notebook, show
output_notebook()

jscode="""
        range.set('start', parseInt(%s));
        range.set('end', parseInt(%s));
    """


s1=figure(width=250, plot_height=250, title=None, tools="pan, wheel_zoom")
s1.line([1, 2, 3], [300, 300, 400], color="navy", alpha=0.5)
s1.extra_y_ranges = {"foo": Range1d(start=1, end=9)}
s1.add_layout(LinearAxis(y_range_name="foo"), 'right')
s1.line([1, 2, 3], [4, 4, 1], color="firebrick", alpha=0.5, y_range_name="foo")


s1.extra_y_ranges['foo'].callback = CustomJS(
        args=dict(range=s1.extra_y_ranges['foo']),
                    code=jscode % (s1.extra_y_ranges['foo'].start,
                                   s1.extra_y_ranges['foo'].end)
            )

show(s1)
+4

1.3.4. Range1d.bounds:

from bokeh.plotting import figure
from bokeh.models import LinearAxis, Range1d
from bokeh.io import show

s1 = figure(width=250, plot_height=250, title=None, tools="pan, wheel_zoom")
s1.line([1, 2, 3], [300, 300, 400], color="navy", alpha=0.5)
s1.extra_y_ranges = {"foo": Range1d(start=1, end=9, bounds=(1,9))}
s1.add_layout(LinearAxis(y_range_name="foo"), 'right')
s1.line([1, 2, 3], [4, 4, 1], color="firebrick", alpha=0.5, y_range_name="foo")

show(s1)
0

Source: https://habr.com/ru/post/1618561/


All Articles