[英]bokeh, two y axis, disable one axis for zoom/ panning
similar to the matplotlib ax.set_navigate(False)
command possible? 类似于matplotlib
ax.set_navigate(False)
命令吗?
Here is a minimal example using ipython notebook. 这是使用ipython Notebook的一个最小示例。
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 is possible to hold the second y axis in place, while zooming and panning in the other y axis? 在另一个y轴上缩放和平移时,是否可以将第二个y轴保持在原位?
Using PanTool dimensions did not help me with this problem. 使用PanTool尺寸无法解决此问题。
Edit: Screenshot inserted: 编辑:插入的屏幕截图:
Blue line is drawn on the first axis, red on the second 在第一个轴上绘制蓝线,在第二个轴上绘制红线
If I zoom in, pan around the x axis, I want the red line to keep in place. 如果放大,请绕x轴平移,我希望红线保持在原位。
You can use the callback
functionality of the second y axis to insert JavaScript code that resets the range to the original values whenever a zoom or pan is executed: 您可以使用第二个y轴的
callback
功能来插入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)
Jakes answer didn't work for me in bokeh 1.3.4 anymore. 在bokeh 1.3.4中,Jakes答案不再对我有用。 It can however simply be done using the Range1d.bounds attribute by now:
但是,现在可以使用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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.