OK, was able to narrow thinks down:
actually it looks like
figure.canvas.mpl_connect('pick_event', function)
does not connect the "function" if it is a class method (...?)
In attachment you will find two files illustrating this:
buggy_pick.py and buggy_pick2.py
Both work nicely with matplotlib 0.93
With matplotlib 1.0 buggy_pick.py does not work while buggy_pick2.py does work.
The only difference is in the PickFig class...

Is it really a bug or I'm doing something wrong ?

Any workaround would be welcome.

Thx,

David

PS. Is it better to discuss this on users or devel list ?

Le 23/09/10 15:42, Ryan May a écrit :
On Thu, Sep 23, 2010 at 3:20 AM, David Trémouilles<david.t...@gmail.com>  wrote:
Hello,

  I've just updated matplotlib to 1.0 svn version from 0.93.
My pyqt4 app use the pick event. Cliking on a point in the graph
triggers an event but with matplotlib 1.0 it does not anymore while
it was working fine with 0.93.
Any idea/help on where I should look for ?

Not without a better idea of what you're doing. I *can* say that both
picking examples work fine for me with the Qt4Agg backend. Can you
create a complete, minimal example that replicates the problem you're
seeing? Without that, I'd just be guessing blindly.

Ryan

import matplotlib
matplotlib.use('Qt4Agg')
import numpy as np
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui


from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar

class MatplotlibFig(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self)
        figure = Figure()
        fig_canvas = FigureCanvasQTAgg(figure)
        fig_toolbar = NavigationToolbar(fig_canvas, self)
        fig_vbox = QtGui.QVBoxLayout()
        fig_vbox.addWidget(fig_canvas)
        fig_vbox.addWidget(fig_toolbar)
        fig_canvas.setParent(self)
        self.setLayout(fig_vbox)
        self.figure = figure

class PickFig(object):
    def __init__(self, fig):
        x = np.arange(10)
        y = np.exp(x)
        ax1 = fig.add_subplot(111)
        selected_flag = np.zeros(x.shape[0],dtype=np.bool)
        ax1.plot(x, y)
        line, = ax1.plot(x, y, 'o', picker=5)
        selected_point, = ax1.plot(x[selected_flag], y[selected_flag], 'ro')
        self.ax1 = ax1
        self.x = x
        self.y = y
        self.fig = fig
        self.selected_flag = selected_flag
        self.selected_point = selected_point
        fig.canvas.mpl_connect('pick_event', self.onpick3)
        fig.canvas.draw()

    def onpick3(self, event):
        print event
        if event.mouseevent.button == 1:
            self.ax1.set_autoscale_on(False)
            ind = event.ind
            self.selected_flag[ind] = not self.selected_flag[ind]
            print self.x[self.selected_flag]
            print 'onpick3 scatter:', ind, np.take(self.x, ind), np.take(self.y, ind)
            self.selected_point.set_data(self.x[self.selected_flag],
                                    self.y[self.selected_flag])
            self.fig.canvas.draw()



class TestFig(MatplotlibFig):
    def __init__(self, parent=None):
        MatplotlibFig.__init__(self, parent)
        PickFig(self.figure)


class MainWin(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.setWindowTitle("Test")
        mat_fig = TestFig(self)
        self.setCentralWidget(mat_fig)
        

def main():
    app = QtGui.QApplication(sys.argv)
    mainwin = MainWin()
    mainwin.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
import matplotlib
matplotlib.use('Qt4Agg')
import numpy as np
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui


from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar

class MatplotlibFig(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self)
        figure = Figure()
        fig_canvas = FigureCanvasQTAgg(figure)
        fig_toolbar = NavigationToolbar(fig_canvas, self)
        fig_vbox = QtGui.QVBoxLayout()
        fig_vbox.addWidget(fig_canvas)
        fig_vbox.addWidget(fig_toolbar)
        fig_canvas.setParent(self)
        self.setLayout(fig_vbox)
        self.figure = figure

class PickFig(object):
    def __init__(self, fig):
        x = np.arange(10)
        y = np.exp(x)
        ax1 = fig.add_subplot(111)
        selected_flag = np.zeros(x.shape[0],dtype=np.bool)
        ax1.plot(x, y)
        line, = ax1.plot(x, y, 'o', picker=5)
        selected_point, = ax1.plot(x[selected_flag], y[selected_flag], 'ro')
        def onpick3(event):
            print event
            if event.mouseevent.button == 1:
                ax1.set_autoscale_on(False)
                ind = event.ind
                selected_flag[ind] = not selected_flag[ind]
                print x[selected_flag]
                print 'onpick3 scatter:', ind, np.take(x, ind), np.take(y, ind)
                selected_point.set_data(x[selected_flag],
                                        y[selected_flag])
                fig.canvas.draw()
        fig.canvas.mpl_connect('pick_event', onpick3)
        fig.canvas.draw()




class TestFig(MatplotlibFig):
    def __init__(self, parent=None):
        MatplotlibFig.__init__(self, parent)
        PickFig(self.figure)


class MainWin(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.setWindowTitle("Test")
        mat_fig = TestFig(self)
        self.setCentralWidget(mat_fig)
        

def main():
    app = QtGui.QApplication(sys.argv)
    mainwin = MainWin()
    mainwin.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to