3つのプロットを持つフィギュアキャンバスがあるとします...2つはimshowでプロットされた同じ寸法の画像で、もう1つは他の種類のサブプロットです。imshowプロットのx軸とy軸をリンクして、一方をズームインすると(NavigationToolbarが提供するズームツールを使用)、もう一方が同じ座標にズームし、一方をパンすると、 、他の鍋も同様です。
scatterやhistogramなどのサブプロットメソッドは、sharexとshareyの軸を指定するkwargsを渡すことができますが、imshowにはそのような構成はありません。
NavigationToolbar2WxAgg(以下に表示)をサブクラス化することで、これを回避する方法をハッキングし始めました...しかし、ここにはいくつかの問題があります。1)これは、キャンバス内のすべてのプロットの軸をリンクします。これは、a.in_axes()のチェックを削除するだけなので、2)これはパンにはうまく機能しましたが、ズームにより、すべてのサブプロットが同じグローバルからズームされましたそれぞれの軸の同じポイントからではなく、ポイント。
誰かが回避策を提案できますか?
どうもありがとう!-アダム
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg
class MyNavToolbar(NavigationToolbar2WxAgg):
def __init__(self, canvas, cpfig):
NavigationToolbar2WxAgg.__init__(self, canvas)
# overrided
# As mentioned in the code below, the only difference here from overridden
# method is that this one doesn't check a.in_axes(event) when deciding which
# axes to start the pan in...
def press_pan(self, event):
'the press mouse button in pan/zoom mode callback'
if event.button == 1:
self._button_pressed=1
elif event.button == 3:
self._button_pressed=3
else:
self._button_pressed=None
return
x, y = event.x, event.y
# push the current view to define home if stack is empty
if self._views.empty(): self.push_current()
self._xypress=[]
for i, a in enumerate(self.canvas.figure.get_axes()):
# only difference from overridden method is that this one doesn't
# check a.in_axes(event)
if x is not None and y is not None and a.get_navigate():
a.start_pan(x, y, event.button)
self._xypress.append((a, i))
self.canvas.mpl_disconnect(self._idDrag)
self._idDrag=self.canvas.mpl_connect('motion_notify_event', self.drag_pan)
# overrided
def press_zoom(self, event):
'the press mouse button in zoom to rect mode callback'
if event.button == 1:
self._button_pressed=1
elif event.button == 3:
self._button_pressed=3
else:
self._button_pressed=None
return
x, y = event.x, event.y
# push the current view to define home if stack is empty
if self._views.empty(): self.push_current()
self._xypress=[]
for i, a in enumerate(self.canvas.figure.get_axes()):
# only difference from overridden method is that this one doesn't
# check a.in_axes(event)
if x is not None and y is not None and a.get_navigate() and a.can_zoom():
self._xypress.append(( x, y, a, i, a.viewLim.frozen(), a.transData.frozen()))
self.press(event)