Re: [Matplotlib-users] MPL with PyQt: different behavior on Windows vs. Linux
Thanks for the tip Darren. Adding this line seems to have done the trick! Very much appreciated. --- On Fri, 6/12/09, Darren Dale wrote: From: Darren Dale Subject: Re: [Matplotlib-users] MPL with PyQt: different behavior on Windows vs. Linux To: "Steve Nicholes" Cc: matplotlib-users@lists.sourceforge.net Date: Friday, June 12, 2009, 6:24 AM On Tue, Jun 9, 2009 at 6:17 PM, Steve Nicholes wrote: Hi, I am writing some code for automated testing via GPIB using MPL and PyQt. To simulate automated data collection while debugging the program, I have added a for loop (see below) after reading in a data file that plots each point one by one. When I run the program in Linux, I see each point appear on the canvas one by one as designed, but when I run the same code in Windows, nothing shows up on the canvas during the for loop. Instead, once the loop has completed, all points appear simulataneously. Is there any reason the why calls to canvas.draw() show nothing when run in Windows? I have seen similar discrepancies between PyQt4 behavior on linux and windows in a few situations. In my experience, a call to PyQt4.QtGui.qApp.processEvents() is sufficient to force an update in your view. Darren -- Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] MPL with PyQt: different behavior on Windows vs. Linux
Thanks John. This doesn't seem to be the cause of my problem, but I appreciate the correction. I wasn't aware that this was such bad practice. I guess it is better to import numpy and matplotlib functions separately then? Thanks again --- On Fri, 6/12/09, John Hunter wrote: From: John Hunter Subject: Re: [Matplotlib-users] MPL with PyQt: different behavior on Windows vs. Linux To: "Steve Nicholes" Cc: matplotlib-users@lists.sourceforge.net Date: Friday, June 12, 2009, 7:02 AM On Wed, Jun 10, 2009 at 12:55 AM, Steve Nicholes wrote: > Thanks John. I hope you aren't receiving this reply twice (my email kicked > me out when I hit send). I actually am importing pylab so it isn't an > entirely qt app. I didn't post all of the code originally b/c it is long > (and it would reveal how poor of a programmer I am :) ), but here are the > relevant sections. The problematic section is in blue. Please let me know > if you need anything else. Importing pylab or pyplot into a GUI app is simply not supported. There is never a reason to do it, and it is fraught with perils. I don't know if this has anything to do with the problem you are experiencing, but you need to remove these imports before we can proceed. JDH -- Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] MPL with PyQt: different behavior on Windows vs. Linux
Hi, I am writing some code for automated testing via GPIB using MPL and PyQt. To simulate automated data collection while debugging the program, I have added a for loop (see below) after reading in a data file that plots each point one by one. When I run the program in Linux, I see each point appear on the canvas one by one as designed, but when I run the same code in Windows, nothing shows up on the canvas during the for loop. Instead, once the loop has completed, all points appear simulataneously. Is there any reason the why calls to canvas.draw() show nothing when run in Windows? I'm really lost on this one and would appreciate it someone can tell me what I'm doing wrong. If you need more info on what I'm doing, please let me know. Thanks in advance, Steve self.data = loadtxt('test_data2.csv',comments = '#',delimiter = ',',skiprows = 0) for i in range(0,len(self.data)): line, = self.plotWidget.canvas.ax.plot([self.data[i,1]], [self.data[i,0]], 'bo') self.plotWidget.canvas.draw() -- Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] MPL with PyQt: different behavior on Windows vs. Linux
Thanks John. I hope you aren't receiving this reply twice (my email kicked me out when I hit send). I actually am importing pylab so it isn't an entirely qt app. I didn't post all of the code originally b/c it is long (and it would reveal how poor of a programmer I am :) ), but here are the relevant sections. The problematic section is in blue. Please let me know if you need anything else. I will try the examples you suggested the next time on I'm a Windows box to see if they behave differently than in Linux. Thanks! #!/usr/bin/env python from PyQt4.QtCore import * from PyQt4.QtGui import * from pylab import * from pulse_ui import Ui_MainWindow from mpl_pyqt4_widget import MPL_Widget class Plot_Widget(QMainWindow, Ui_MainWindow): def __init__(self, parent = None): QMainWindow.__init__(self) self.setupUi(self) self.label_checkmark.hide() self.usr_click = 1 self.abort_run = 0 self.R = 1.6e-19/(6.626e-34*3e8/(float(self.lineEdit_wavelength.text())*10**-9)) self.facet_fraction = 0.5 self.lengths = [] self.etads = [] self.data = loadtxt('test_data.csv',comments = '#',delimiter = ',',skiprows = 0) self.slider_stop.setMaximum(len(self.data)) QObject.connect(self.plotBtn, SIGNAL("clicked()"),self.plotData) QObject.connect(self.pushButton_abort,SIGNAL('clicked()'),self.abort) def abort(self): self.abort_run = 1 def plotSetupMain(self): self.plotWidget.canvas.ax.cla() self.plotWidget.canvas.ax.set_title("Pulsed LIV") self.plotWidget.canvas.ax.title.set_fontsize(10) self.plotWidget.canvas.ax.set_xlabel("Current (mA)", fontsize = 9) self.plotWidget.canvas.ax.set_ylabel("Light (mW)", fontsize = 9) labels_x = self.plotWidget.canvas.ax.get_xticklabels() labels_y = self.plotWidget.canvas.ax.get_yticklabels() for xlabel in labels_x: xlabel.set_fontsize(8) for ylabel in labels_y: ylabel.set_fontsize(8) ylabel.set_color('b') self.plotWidget.canvas.ax.grid() def plotData(self): self.plotSetupMain() self.label_checkmark.hide() del self.plotWidget.canvas.ax.lines[:] for i in range(0,len(self.data)): line, = self.plotWidget.canvas.ax.plot([self.data[i,1]], [self.data[i,0]], 'bo') self.plotWidget.canvas.draw() if self.abort_run == 1: break if self.abort_run == 0: self.plotWidget.canvas.ax.plot(self.data[:,1], self.data[:,0], 'bo') self.usr_click = 0 self.slider_start.setValue(len(self.data)/2) self.usr_click = 0 self.slider_stop.setValue(len(self.data)) a,b = polyfit(self.data[self.slider_start.value():self.slider_stop.value(),1],self.data[self.slider_start.value():self.slider_stop.value(),0+self.acquire],1) fit = a*self.data[:,1] + b self.plotWidget.canvas.ax.plot(self.data[:,1], fit, 'g-',linewidth = '2') self.plotWidget.canvas.ax.axvline(self.data[self.slider_start.value()-1,1],linestyle = '--',color = 'r') self.plotWidget.canvas.ax.axvline(self.data[self.slider_stop.value()-1,1],linestyle = '--',color = 'k') self.plotWidget.canvas.draw() self.label_etad.setText('%.3f' % (a*self.R/self.facet_fraction)) self.label_ith.setText('%.3f' % (-b/a) + ' mA') else: self.abort_run = 0 --- On Tue, 6/9/09, John Hunter wrote: From: John Hunter Subject: Re: [Matplotlib-users] MPL with PyQt: different behavior on Windows vs. Linux To: "Steve Nicholes" Cc: matplotlib-users@lists.sourceforge.net Date: Tuesday, June 9, 2009, 6:25 PM On Tue, Jun 9, 2009 at 5:17 PM, Steve Nicholes wrote: > I am writing some code for automated testing via GPIB using MPL and PyQt. > To simulate automated data collection while debugging the program, I have > added a for loop (see below) after reading in a data file that plots each > point one by one. When I run the program in Linux, I see each point appear > on the canvas one by one as designed, but when I run the same code in > Windows, nothing shows up on the canvas during the for loop. Instead, once > the loop has completed, all points appear simulataneously. Is there any > reason the why calls to canvas.draw() show nothing when run in Windows? I'm > really lost on this one and would appreciate it someone can tell me what I'm > doing wrong. If you need more info on what I'm doing, please let me know. It would help if we could see the whole
Re: [Matplotlib-users] MPL with PyQt: different behavior on Windows vs. Linux
There is definitely something weird going on here. It could still be a bad command on my part, but I cannot get Windows to plot interactively if I embed it in pyqt. I even tried adapting one of the qt examples from the matplotlib homepage and I still have the same problem (i.e., it will only plot point by point in Linux). I'm attaching two files to illustrate: (1) a simple program that works interactively in both Windows and Linux without qt; and (2) the example from the homepage with my code inserted (which is the same code that I used in the first attachment that behaves properly). I'm wondering if there is some issue with qt and Windows at work. Any thoughts? Thanks, Steve --- On Tue, 6/9/09, John Hunter wrote: From: John Hunter Subject: Re: [Matplotlib-users] MPL with PyQt: different behavior on Windows vs. Linux To: "Steve Nicholes" Cc: matplotlib-users@lists.sourceforge.net Date: Tuesday, June 9, 2009, 6:25 PM On Tue, Jun 9, 2009 at 5:17 PM, Steve Nicholes wrote: > I am writing some code for automated testing via GPIB using MPL and PyQt. > To simulate automated data collection while debugging the program, I have > added a for loop (see below) after reading in a data file that plots each > point one by one. When I run the program in Linux, I see each point appear > on the canvas one by one as designed, but when I run the same code in > Windows, nothing shows up on the canvas during the for loop. Instead, once > the loop has completed, all points appear simulataneously. Is there any > reason the why calls to canvas.draw() show nothing when run in Windows? I'm > really lost on this one and would appreciate it someone can tell me what I'm > doing wrong. If you need more info on what I'm doing, please let me know. It would help if we could see the whole program. Ie, I assume this is a pure qt app with no import of pyplot/pylab, but w/o seeing any code I cannot be sure. Also, check the qt examples at http://matplotlib.sourceforge.net/examples/animation/index.html and see if they work on windows. If so, perhaps you can borrow inspiration from them. If not, perhaps we need to do something different for qt/windows animation. JDH JDH from pylab import * from time import sleep x = linspace(0,10,10) y = linspace(0,10,10) ion() ax = subplot(111,autoscale_on=True) for i in range(0,len(x)): line = plot([x[i]], [y[i]],'-o') draw() sleep(4)import sys, os, random from PyQt4 import QtGui, QtCore #from pylab import * from numpy import arange, sin, pi, linspace from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure progname = os.path.basename(sys.argv[0]) progversion = "0.1" class MyMplCanvas(FigureCanvas): """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.).""" def __init__(self, parent=None, width=5, height=4, dpi=100): fig = Figure(figsize=(width, height), dpi=dpi) self.axes = fig.add_subplot(111) # We want the axes cleared every time plot() is called self.axes.hold(False) self.compute_initial_figure() # FigureCanvas.__init__(self, fig) self.setParent(parent) FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) #def compute_initial_figure(self): # pass class MyStaticMplCanvas(MyMplCanvas): """Simple canvas with a sine plot.""" def compute_initial_figure(self): t = arange(0.0, 3.0, 0.01) s = sin(2*pi*t) self.axes.plot(t, s) class MyDynamicMplCanvas(MyMplCanvas): """A canvas that updates itself every second with a new plot.""" def __init__(self, *args, **kwargs): MyMplCanvas.__init__(self, *args, **kwargs) timer = QtCore.QTimer(self) QtCore.QObject.connect(timer, QtCore.SIGNAL("timeout()"), self.update_figure) timer.start(1000) def compute_initial_figure(self): #self.axes.plot([0, 1, 2, 3], [1, 2, 0, 4], 'r') print 'nothing' def update_figure(self): # Build a list of 4 random integers between 0 and 10 (both inclusive) self.axes.hold(True) x = linspace(0,11,50) y = linspace(0,10,50) for i in range(0,len(y)): self.axes.plot([x[i]], [y[i]], 'ro') print i, x[i], y[i] self.draw() class ApplicationWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setWindowTitle("application main window") self.file_menu = QtGui.QMenu('&F
[Matplotlib-users] Matplotlib 1.0 upgrade breaks latex functionality?
Hello, I recently upgraded matplotlib v0.98.5 to 1.0. Now when I try to plot data using latex for the figure labels my scripts fail. I have not changed my code so I'm not sure where the error is coming from. I have tried reinstalling and updating MikTex and Ghostscript but that has not helped (I'm running Windows 7 and Python 2.6). The actual error I get is below. Any thoughts? Thanks, Steve Traceback (most recent call last): File "C:\Python26\lib\site-packages\matplotlib\backends\backend_qt4.py", line 215, in resizeEvent self.draw() File "C:\Python26\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 130, in draw FigureCanvasAgg.draw(self) File "C:\Python26\lib\site-packages\matplotlib\backends\backend_agg.py", line 394, in draw self.figure.draw(self.renderer) File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 798, in draw func(*args) File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python26\lib\site-packages\matplotlib\axes.py", line 1934, in draw a.draw(renderer) File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python26\lib\site-packages\matplotlib\axis.py", line 1017, in draw tick.draw(renderer) File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python26\lib\site-packages\matplotlib\axis.py", line 236, in draw self.label2.draw(renderer) File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python26\lib\site-packages\matplotlib\text.py", line 524, in draw bbox, info = self._get_layout(renderer) File "C:\Python26\lib\site-packages\matplotlib\text.py", line 307, in _get_layout ismath=ismath) File "C:\Python26\lib\site-packages\matplotlib\backends\backend_agg.py", line 171, in get_text_width_height_descent renderer=self) File "C:\Python26\lib\site-packages\matplotlib\texmanager.py", line 608, in get_text_width_height_descent page = iter(dvi).next() File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 65, in __iter__ have_page = self._read() File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 121, in _read self._dispatch(byte) File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 209, in _dispatch self._fnt_def(k, c, s, d, a, l, n) File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 370, in _fnt_def vf = _vffile(n[-l:]) File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 871, in _vffile return _fontfile(texname, Vf, '.vf', _vfcache) File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 860, in _fontfile result = class_(filename) File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 479, in __init__ self._read() File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 121, in _read self._dispatch(byte) File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 508, in _dispatch Dvi._dispatch(self, byte) File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 209, in _dispatch self._fnt_def(k, c, s, d, a, l, n) File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 546, in _fnt_def Dvi._fnt_def(self, k, *args) File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 372, in _fnt_def self.fonts[k] = DviFont(scale=s, tfm=tfm, texname=n, vf=vf) File "C:\Python26\lib\site-packages\matplotlib\dviread.py", line 418, in __init__ nchars = max(tfm.width.iterkeys()) + 1 AttributeError: 'NoneType' object has no attribute 'width' Traceback (most recent call last): File "C:\Users\steve.nicholes\Documents\Beamformer\Design\SOA\SOA Design.py", line 333, in show() File "C:\Python26\lib\site-packages\matplotlib\backends\backend_qt4.py", line 71, in show figManager.canvas.draw() File "C:\Python26\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 130, in draw FigureCanvasAgg.draw(self) File "C:\Python26\lib\site-packages\matplotlib\backends\backend_agg.py", line 394, in draw self.figure.draw(self.renderer) File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 798, in draw func(*args) File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python26\lib\site-packages\matplotlib\axes.py", line 1934, in draw a.draw(renderer) File "C:\Python26\lib\site-packages