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 :slight_smile: ), 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 = aself.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 <jdh2358@…287…>** wrote:

From: John Hunter <jdh2358@…287…>
Subject: Re: [Matplotlib-users] MPL with PyQt: different behavior on Windows vs. Linux
To: “Steve Nicholes” <emailaddress_scn@…9…>
Cc: matplotlib-users@…813…ourceforge.net
Date: Tuesday, June 9, 2009, 6:25 PM

On Tue, Jun 9, 2009 at 5:17 PM, Steve > Nicholes<emailaddress_scn@…9…> 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

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

···

On Wed, Jun 10, 2009 at 12:55 AM, Steve Nicholes<emailaddress_scn@...9...> 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 :slight_smile: ), but here are the
relevant sections. The problematic section is in blue. Please let me know
if you need anything else.