Python 如何更改使用mpl.to_bokeh创建的bokeh绘图上的工具?

Python 如何更改使用mpl.to_bokeh创建的bokeh绘图上的工具?,python,matplotlib,plot,bokeh,Python,Matplotlib,Plot,Bokeh,我试图在x和y方向显示一个复杂的信号,并在ipython笔记本中提供bokeh提供的很棒的交互式工具。特别是,我想限制滚轮缩放到x轴,但在使用mpl.to_bokeh()后,我看不出如何执行此操作。在使用mpl.to_bokeh()之前,是否有办法设置默认工具 以下是我想使用的示例图: import matplotlib.pyplot as plt import bokeh.plotting as blt from bokeh import mpl from bokeh.plotting imp

我试图在x和y方向显示一个复杂的信号,并在ipython笔记本中提供bokeh提供的很棒的交互式工具。特别是,我想限制滚轮缩放到x轴,但在使用
mpl.to_bokeh()
后,我看不出如何执行此操作。在使用
mpl.to_bokeh()
之前,是否有办法设置默认工具

以下是我想使用的示例图:

import matplotlib.pyplot as plt
import bokeh.plotting as blt
from bokeh import mpl
from bokeh.plotting import show
blt.output_notebook()
import numpy as np

blt.figure(tools='xwheel_zoom') # this doesn't help
x= np.arange(100)/100
y= np.exp(1j*2*np.pi*x)
ax= plt.subplot(211)
plt.plot(x,y.real)
plt.subplot(212, sharex=ax)
plt.plot(x,y.imag)
fig= mpl.to_bokeh(name='subplots')

不幸的是,使用MPL compat层进行此操作,仅使用一个绘图就已经有点困难了。我不确定目前是否有任何方法可以通过网格图和MPL来实现这一点。但是,如果您直接使用bokeh API,这是非常简单的。如果这是您的一个选项,并且很有帮助:

from bokeh.plotting import figure, gridplot, show
import numpy as np

x = np.arange(100)/100
y = np.exp(1j*2*np.pi*x)

p1 = figure(tools='xwheel_zoom')
p1.line(x,y.real)

p2 = figure(tools='xwheel_zoom')
p2.line(x,y.imag)

grid = gridplot([[p1, p2]])
show(grid)

谢谢你的回复。您是否知道将x轴锁定在一起的方法?是的,您只需要共享范围。因此,在上面的代码中,添加
p2=figure(tools='xwheel\u zoom',x\u range=p1.x\u range)
以在x轴上进行链接平移这已不再可能。自Bokeh 12.5(2017年4月)起,和
mpl.to_Bokeh()
已被删除。另见bryevdv。