Hi,

I don't have conclusive proof, .. but I suspect that the draw() of a graph in a pyGTK application is order of magnitudes slower than I can plot the same data in the default Tk graphing widget.

i.e. 5 sec in tk, ... and >1 minute in gtk

Obvious question, ... is this a know issue?
Is there any tricks in gtk to speed up the draw()

Attached is a heavily snipped example of bits and pieces of my code, maybe I have structured my program incorrectly?

Thanks for any comments
Steve

--
NO to the Microsoft Office format as an ISO standard
http://www.noooxml.org/petition

import matplotlib
matplotlib.use('GTK')


from matplotlib.figure import Figure
from matplotlib.axes import Subplot

from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar

           : :
        <snip>
           : :
try:
    print 'Trying import pygtk',
    import pygtk
    pygtk.require("2.0")
    print '...success'
except:
    print '...failure'
    pass

try:
    print 'Trying import gtk',
    import gtk
    import gtk.glade
    import gobject
    print '...success'
except:
    print '...failure'
    sys.exit(1)

           : :
        <snip>
           : :


class appGUI(gobject.GObject):
    __gsignals__ = {
                    'stevesSignal': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_FLOAT,)),
                    'gui-StartTests':  (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,[])

                    }
    SpeedCheckBoxNames = ['1p25K_Btn', '2p5K_Btn', '5K_Btn','12p5K_Btn', '25K_Btn', '37p5K_Btn', '75K_Btn', '100K_Btn', '150K_Btn']

    def __init__(self):
        gobject.GObject.__init__(self)
           : :
        <snip>
           : :

        #setup matplotlib stuff on second notebook page (Profile)
        self.profile_figure = Figure(figsize=(16,4), dpi=72)
        self.profile_axis = self.profile_figure.add_subplot(111)
        self.profile_axis.set_xlabel('Fringe position')
        self.profile_axis.set_ylabel('Force (mA)')
        self.profile_axis.set_title("OBE6 VoiceCoil Force Profile")
        self.profile_axis.grid(True)

        self.profile_axis.xaxis.grid(True, which="major", linestyle='-')
        self.profile_axis.xaxis.grid(True, which="minor")

        self.profile_canvas = FigureCanvas(self.profile_figure) # a gtk Drawing area
        self.profile_canvas.show()
        
        self.profile_graphview = self.wTree.get_widget("profile_vbox")
        
        if self.profile_graphview == None:
            self.log.error( 'profile_graphview is empty')
        self.profile_graphview.pack_start(self.profile_canvas, True, True)
        
        self.profile_toolbar = NavigationToolbar(self.profile_canvas, self.win)

        self.profile_toolbar.set_size_request(-1, 25)

        self.navBox = gtk.HBox(False, 10)
        self.profile_graphview.pack_start(self.navBox, False, False)
        self.navBox.set_size_request(35, 35)
        self.navBox.show()
        
        self.combo = gtk.combo_box_new_text()
        
        self.combo.set_size_request(-1, 25)
        self.combo.show()
        
        self.sep = gtk.VSeparator()
        self.sep.show()

        self.navBox.pack_start(self.combo, False, False)
        self.navBox.pack_start(self.sep, False, False)
        self.navBox.pack_start(self.profile_toolbar, True, True)
           : :
        <snip>
           : :

    def plotFrictionProfile(self, widget):

        #Check what data (speed) to plot
        spdIdx = self.combo.get_active()
        spdToShow = self.cntlr.testingSpeeds[spdIdx]
        
        self.log.debug("Starting plot ..................")
        #start = time.clock()
        figBG   = 'w'        # the figure background color
        axesBG  = '#f6f6f6'  # the axies background color
        purple = '#660033'
        red = 'r'
        green = 'g'
        blue = 'b'
        textsize = 8        # size for axes text
        
        while True:
            try:
                self.log.info( 'Clear Axis')
                # empty axis if neccesary, and reset title and stuff

                #TODO: Need to remove any left over axis from the figure first
                self.profile_axis.clear()

                self.profile_axis.set_xlabel('Samples')
                self.profile_axis.set_ylabel('VcSense (%s)'% self.units_str)
                self.profile_axis.set_title("%s - VoiceCoil Force @ %s\n %s" % (self.inst.config.get_property('SerialNo'),self.cntlr.speedMap[spdToShow][self.cntlr.SM_NAME], self.cntlr.starttime.ctime() ) )
                self.profile_axis.grid(True)
                self.profile_axis.xaxis.grid(True, which="major", linestyle='-')
                self.profile_axis.xaxis.grid(True, which="minor")


                #Due to slow draw(), slower speeds need to be decimated to reduce data
                if spdToShow == SPEED5Kz:
                    dataToPlot = Smooth(self.d_force[spdIdx], 4, 2, 0, 4)
                elif spdToShow == SPEED2p5Kz:
                    dataToPlot = Smooth(self.d_force[spdIdx], 4, 2, 0, 8)
                else:
                    dataToPlot = Smooth(self.d_force[spdIdx], 4, 2, 0, 1)
                    
                    
                r = self.profile_axis.plot(dataToPlot, color=blue)
                
                #This is were all the time is wasted (if i dont decimate the data it in the order of minutes for the slowest speed)
                print '### BEFORE draw() ####'
                self.profile_canvas.draw()
                print '### AFTER draw() ####'
                break
            
            except ValueError:
                self.log.exception( '#$^#$^#$^ FAILED TO CREATE PROFILE GRAPH #$^#$^#$^')
                break

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to