'canvas.mpl_connect'在类内部不起作用

时间:2019-01-23 16:32:59

标签: python matplotlib canvas

我正在尝试对event.xdata上的鼠标按下事件做出响应(返回fig的值)。但这是行不通的。谁能告诉我我的代码有什么问题吗?谢谢你们。

class ImDisp(mywindow):
    def __init__(self):
        super(ImDisp,self).__init__()

    def BsFig(self,rd,daxis,taxis):
        pos = self.horizontalSlider.value()
        amplim = [self.AmpMinEdit.text(),self.AmpMaxEdit.text()]
        dispopt = [int(self.WindowSizeEdit.text()),int(self.SlidePrecEdit.text())]

        plt.ioff()
        plt.close()
        fig,ax = plt.subplots()
        subwindowsize=dispopt[0]
        slideprecision=dispopt[1]
        d_windowstep = (daxis[-1] - subwindowsize)/(slideprecision-0)      
        x_windowmin = int(round((0+pos*d_windowstep)/(daxis[1]-daxis[0])))
        x_windowmax = x_windowmin+int(round(subwindowsize/(daxis[1]-daxis[0])))
        plt.imshow(rd[:,x_windowmin:x_windowmax], cmap='gray',vmin=amplim[0], vmax=amplim[1], extent=[daxis[x_windowmin], daxis[x_windowmax], taxis[-1], taxis[0]], aspect='auto')
        ax.set_xlabel('D')
        ax.set_ylabel('T')

        fig.canvas.mpl_connect('button_press_event',self.BsInf)
        bs = FigureCanvas(fig)

        self.mainDisp.setWidget(bs)       
        return bs

    def BsInf(self,event):                          
        bs_d=event.xdata
        bs_t=event.ydata
        print(bs_d)

0 个答案:

没有答案