having trouble plotting second figure

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

having trouble plotting second figure

oneillp111
This post has NOT been accepted by the mailing list yet.
My first attempt at a GUI, using wxpython and matplotlib.  I have the GUI working fine, when a part number is entered and a  button is pressed, the function generates a grid and a coinciding line plot. Now if the user enters a different part number and presses the button again, without closing the plot, the GUI freezes and eventually crashes.   Ideally i would like to automatically close the plot ,if it is open, when the button is pressed, but I would also settle for just opening a new figure.  I cant seem to figure out how to do that, any help would be great!!  Function for plotting is below


def compMonth(self, event):
       
             
        partNumber = self.partText.GetValue()
        csvfile = open(powerfile)
        datareader = csv.reader(csvfile, delimiter = ',')
        compCount = 0
        compFails = []
        compFinal = {}
        performance = []
        serials =[]

        for row in self.datarows:  
            if (row[1] == partNumber and  row[9] == 'COMPONENT DEFECT' ):
                compCount += 1
                serials.append(row[0])
                if row[7] == '':
                   
                    compFails.append(row[13])
                else:
                    compFails.append(row[7])
        #print compFails
        c = Counter(compFails).items()
        c.sort(key=itemgetter(1))
        compFails.sort(key=Counter(compFails).get, reverse=True)
        #print compFails
        #print compFails
        for item in compFails:
            #print item
            compFinal[item] = compFails.count(item)
        #print compFinal
        count = len(compFinal)
        #print count
        frame = gridForm()
       
        frame.myGrid.SetCellValue(0,0, "Failure")
        frame.myGrid.SetCellValue(0,1, "Count")
        frame.myGrid.SetCellValue(0,2, "Percent Total")
        y=1
        x=0
        totalCount = sum(compFinal.values())
        for key in compFinal:
            percentage = "%.0f%%" % (100 * compFinal[key]/totalCount)
           
            frame.myGrid.SetCellValue(y,x,key)
            frame.myGrid.SetCellValue(y,(x + 1),str(compFinal[key]))
            frame.myGrid.SetCellValue(y,(x + 2), str(percentage))
            y += 1
            performance.append(compFinal[key])
        labels, values = zip(*c)
        indexes = np.arange(len(labels))
       
       
        plt.bar(indexes, values, align='center',)
        plt.xticks(indexes, labels, rotation = 'vertical')
        plt.ylabel('Number of Failures')
        plt.title('627 Pareto for ' + partNumber)

        frame.Show()
        plt.show()
Loading...