[Matplotlib-users] Matplotlib and PySide ?
Hello, Does anybody know if matplotlib work with pyside ? If it does how to use matplotib with pyside ? Thanks, David -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Mouse event blocked in 1.0 but works with 0.93 ?
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 ? Thanks in advance, David -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Mouse event blocked in 1.0 but works with 0.93 ?
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 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
Re: [Matplotlib-users] Mouse event blocked in 1.0 but works with 0.93 ? (Solved)
Wonderful ! This does indeed solve my issue. Many many thanks, David Le 23/09/10 17:35, Ryan May a écrit : > On Thu, Sep 23, 2010 at 9:16 AM, David Trémouilles > wrote: >> 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. > > Technically, you're doing something sort of wrong, though it's very > subtle. And it just so happens that the way the code for callbacks was > reworked that this even showed up. > In this code: > > class TestFig(MatplotlibFig): > def __init__(self, parent=None): > MatplotlibFig.__init__(self, parent) > PickFig(self.figure) > > You create a PickFig, but since you don't assign it to anything, it > gets garbage collected and (eventually) removed from the callbacks. > Previously, the callback registry would have a reference to the > callbacks, which would have kept PickFig alive. This was changed to > eliminate some resource leaks. The fix is simple, just save the > PickFig as a member of TestFig: > > self.pf = PickFig(self.figure) > > That fixes the problem for me. > > Ryan > -- 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
Re: [Matplotlib-users] Matplotlib and PySide ?
> On Wed, Sep 15, 2010 at 3:03 AM, David Trémouilles <mailto:david.t...@gmail.com>> wrote: > > Hello, > > Does anybody know if matplotlib work with pyside ? > If it does how to use matplotib with pyside ? > > Thanks, > > David > > > David, > > I am not familiar with PySide, so I looked it up. Please correct me if > I am wrong, but it appears to be an alternative to PyQt for licensing > reasons, and the FAQ says that it is API compatible. On the python side > of matplotlib, I wonder if using PySide would be as simple as just > replacing all of the "import PyQt" or "import PyQt4" with "import > PySide" (and all the "from PyQt import ..."). > > Does PySide still use the same compiled Qt libraries that PyQt uses? If > so, then I don't *think* you need to recompile the Qt backends, but I am > not entirely sure. > > Good luck! > Ben Root > Hi Ben, I did try to roughly replace PyQt4 import by PySide import in my installed matplotlib but pyplot.plot function led to a seg fault... (PyQt and PySide where indeed compiled with the same Qt lib) I'm not skilled enough to go further on... Thanks for your help, David -- 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
[Matplotlib-users] interrupted line with maskedarray (normal behavior ?)
Hi, I've just start playing with maskedarray (the new implementation) using fresh svn matplotib (0_91 maintenance). Plotting masked array does not behave as I would have expected. Indeed when drawing a "line graph" the masked walues interrupted the line (see attach example). I would prefer to see a continues line... Is it the expected behavior? Is there a way to change it? Thanks in advance, David import pylab import maskedarray as ma x = ma.arange(10) y = ma.sin(x/10.0) y[2]=ma.masked pylab.plot(x,y,'-o') pylab.show() <>- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] interrupted line with maskedarray (normal behavior ?)
Thanks Jeff, I think now I get the purpose of maskedearray the way it is used in matplotlib. I have a slightly different objective: I just want to remove outliers from my curves. I think I will still play with maskedarray and used the compressed() function before 'sending' to matplotlib. Any comments on that, any other idea? Thanks, David Jeff Whitaker a écrit : > David Trémouilles wrote: >> Hi, >> >> I've just start playing with maskedarray (the new implementation) >> using fresh svn matplotib (0_91 maintenance). >> Plotting masked array does not behave as I would have expected. >> Indeed when drawing a "line graph" the masked walues interrupted the >> line (see attach example). > > David: Yes, this is the correct behavior. The masked values are > treated as missing data. No attempt is made to fill, or interpolate, > the missing data. >> I would prefer to see a continues line... > > Then you should interpolate the missing values yourself. I think it > would be unwise for matplotlib to guess how you might want to do that. > > -Jeff >> Is it the expected behavior? Is there a way to change it? >> >> Thanks in advance, >> >> David >> >> >> >> >> - >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2008. >> http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ >> >> >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] interrupted line with maskedarray (normal behavior ?)
Thank you very much Pierre! You made me discover boolean index (numpy is fantastic !) In the mean time, I now understand the purpose of maskedarray that I totally missed at a first sight. Thanks to all of you, David Pierre GM a écrit : > On Sunday 10 February 2008 12:40:38 David Trémouilles wrote: > >> I have a slightly different objective: I just want to remove outliers >> from my curves. I think I will still play with maskedarray and used the >> compressed() function before 'sending' to matplotlib. >> Any comments on that, any other idea? > > So, you have two arrays x and y, with missing values in y that you don't want > to plot ? > Assuming that your arrays are 1D, you can try something like: > plot(x[logical_not(y.mask)], y.compressed()) > in order to ensure that the x and y to be plotted have the same size. > > Note that in this simple case, you don't need masked arrays, you just want to > plot point satisfying a given condition, right ? > So: > condition = (y>=min_value) & (y<= max_value) > plot(x[condition],y[condition]) > will give the same results. > > - > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users