From: <jb...@us...> - 2010-09-28 21:22:14
|
Revision: 625 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=625&view=rev Author: jblance Date: 2010-09-28 21:22:07 +0000 (Tue, 28 Sep 2010) Log Message: ----------- Extra debug in drawArea, to attempt to determine graphing issues Modified Paths: -------------- pytrainer/trunk/pytrainer/gui/drawArea.py pytrainer/trunk/pytrainer/main.py Modified: pytrainer/trunk/pytrainer/gui/drawArea.py =================================================================== --- pytrainer/trunk/pytrainer/gui/drawArea.py 2010-09-28 03:39:34 UTC (rev 624) +++ pytrainer/trunk/pytrainer/gui/drawArea.py 2010-09-28 21:22:07 UTC (rev 625) @@ -26,415 +26,436 @@ import logging class DrawArea: - def __init__(self, vbox = None, window = None): - logging.debug('>>') - #self.figure = Figure(figsize=(6,4), dpi=72) - #self.axis = self.figure.add_subplot(111) - self.vbox = vbox - self.window = window - #self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea - #self.drawDefault() - self.NEARLY_ZERO = 0.0000000000000000000001 - logging.debug('<<') + def __init__(self, vbox = None, window = None): + logging.debug('>>') + #self.figure = Figure(figsize=(6,4), dpi=72) + #self.axis = self.figure.add_subplot(111) + self.vbox = vbox + self.window = window + #self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea + #self.drawDefault() + self.NEARLY_ZERO = 0.0000000000000000000001 + logging.debug('<<') - def stadistics(self,type,xvalues,yvalues,xlabel,ylabel,title,color=None,zones=None): - logging.debug('>>') - if len(xvalues[0]) < 1: - #self.drawDefault() - return False - #logging.debug('xvalues: '+str(xvalues)) - #logging.debug('yvalues: '+str(yvalues)) - #logging.debug("Type: "+type+" | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) - if type == "bars": - self.drawBars(xvalues,yvalues,xlabel,ylabel,title,color) - elif type == "plot": - self.drawPlot(xvalues,yvalues,xlabel,ylabel,title,color,zones) - elif type == "pie": - self.drawPie(xvalues,yvalues,xlabel,ylabel,title,color,zones) - logging.debug('<<') + def stadistics(self,type,xvalues,yvalues,xlabel,ylabel,title,color=None,zones=None): + logging.debug('>>') + if len(xvalues[0]) < 1: + #self.drawDefault() + return False + #logging.debug('xvalues: '+str(xvalues)) + #logging.debug('yvalues: '+str(yvalues)) + #logging.debug("Type: "+type+" | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) + if type == "bars": + self.drawBars(xvalues,yvalues,xlabel,ylabel,title,color) + elif type == "plot": + self.drawPlot(xvalues,yvalues,xlabel,ylabel,title,color,zones) + elif type == "pie": + self.drawPie(xvalues,yvalues,xlabel,ylabel,title,color,zones) + logging.debug('<<') - def drawBars(self,xvalues,yvalues,xlabel,ylabel,title,color): - logging.debug('>>') - logging.debug("Type: bars | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) - self.removeVboxChildren() - figure = Figure(figsize=(6,4), dpi=72) - numCols=len(xvalues[0]) - xmod = 0.4 - self.showGraph=False - axis = figure.add_subplot(111) + def drawBars(self,xvalues,yvalues,xlabel,ylabel,title,color): + logging.debug('>>') + logging.debug("Type: bars | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) + self.removeVboxChildren() + figure = Figure(figsize=(6,4), dpi=72) + logging.debug("Figure: %s" % str(figure) ) + numCols=len(xvalues[0]) + xmod = 0.4 + self.showGraph=False + axis = figure.add_subplot(111) + logging.debug("Axis: %s" % str(axis) ) - if len(xvalues) == 1: #One axis - barWidth = 0.8 - barOffset = 0.1 - elif len(xvalues) == 2: #Twin axes - barWidth = 0.4 - barOffset = 0.1 - else: #Error - return + if len(xvalues) == 1: #One axis + barWidth = 0.8 + barOffset = 0.1 + logging.debug("One axis, barWidth %f, barOffset %f" % (barWidth, barOffset) ) + elif len(xvalues) == 2: #Twin axes + barWidth = 0.4 + barOffset = 0.1 + logging.debug("Twin axes, barWidth %f, barOffset %f" % (barWidth, barOffset) ) + else: #Error + logging.debug("Error: invalid number of axes" ) + return - axis.set_xlabel(xlabel[0]) - axis.set_ylabel(ylabel[0]) - xvals = [x+barOffset for x in range(0, numCols)] - yvals = [0] * numCols - for i in range(0, numCols): - yval = yvalues[0][i] - if float(yval) > 0.0: - self.showGraph=True - else: - yval = self.NEARLY_ZERO - yvals[i] = yval - if self.showGraph: - axis.bar(xvals, yvals, barWidth, color=color[0], align='edge') - else: #Only zero results - pass + axis.set_xlabel(xlabel[0]) + axis.set_ylabel(ylabel[0]) + logging.debug("Labels set x: %s, y: %s" % (xlabel[0], ylabel[0]) ) + xvals = [x+barOffset for x in range(0, numCols)] + yvals = [0] * numCols + for i in range(0, numCols): + yval = yvalues[0][i] + if float(yval) > 0.0: + self.showGraph=True + else: + yval = self.NEARLY_ZERO + yvals[i] = yval + if self.showGraph: + logging.debug("Drawing bars") + axis.bar(xvals, yvals, barWidth, color=color[0], align='edge') + else: #Only zero results + logging.debug("No results to draw") + pass - axis.grid(True) - axis.set_title("%s" %(title[0])) - for tl in axis.get_yticklabels(): - tl.set_color('%s' %color[0]) + axis.grid(True) + axis.set_title("%s" %(title[0])) + logging.debug("Setting title to: %s" % title[0]) + for tl in axis.get_yticklabels(): + logging.debug("Setting ticklabel color %s" % color[0]) + tl.set_color('%s' %color[0]) - if len(xvalues) == 2: #Display twin axis - ax2 = axis.twinx() - xvals = [x+barOffset+barWidth for x in range(0, numCols)] - for i in range(0, numCols): - yval = yvalues[1][i] - if float(yval) > 0.0: - self.showGraph=True - else: - yval = self.NEARLY_ZERO - yvals[i] = yval - if self.showGraph: - ax2.bar(xvals, yvals, barWidth, color=color[1], align='edge') - ax2.set_ylabel(ylabel[1]) - else: #Only zero results - pass - for tl in ax2.get_yticklabels(): - tl.set_color('%s' %color[1]) - axis.set_title("%s vs %s" %(title[0],title[1])) + if len(xvalues) == 2: #Display twin axis + ax2 = axis.twinx() + logging.debug("Axis 2: Twin axis: %s " % str(ax2)) + xvals = [x+barOffset+barWidth for x in range(0, numCols)] + for i in range(0, numCols): + yval = yvalues[1][i] + if float(yval) > 0.0: + self.showGraph=True + else: + yval = self.NEARLY_ZERO + yvals[i] = yval + if self.showGraph: + logging.debug("Axis 2: Drawing bars") + ax2.bar(xvals, yvals, barWidth, color=color[1], align='edge') + logging.debug("Axis 2: Label set y: %s" % (ylabel[1]) ) + ax2.set_ylabel(ylabel[1]) + else: #Only zero results + logging.debug("Axis 2: No results to draw") + pass + for tl in ax2.get_yticklabels(): + tl.set_color('%s' %color[1]) + logging.debug("Axis 2: Setting ticklabel color %s" % color[1]) + _title = "%s vs %s" %(title[0],title[1]) + logging.debug("Axis 2: Setting title to: %s" % _title) + axis.set_title(_title) + + logging.debug("Setting x ticks") + tickLocations = [x+0.5 for x in xrange(0, numCols)] + axis.set_xticks(tickLocations) + axis.set_xticklabels(xvalues[0]) + logging.debug("Setting x limits") + axis.set_xlim(0, numCols) + + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea + logging.debug("Got canvas: %s" % (str(canvas))) + canvas.show() + logging.debug("Adding canvas to vbox") + self.vbox.pack_start(canvas, True, True) + #toolbar = NavigationToolbar(canvas, self.window) + #self.vbox.pack_start(toolbar, False, False) - tickLocations = [x+0.5 for x in xrange(0, numCols)] - axis.set_xticks(tickLocations) - axis.set_xticklabels(xvalues[0]) - axis.set_xlim(0, numCols) - - canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea - canvas.show() - self.vbox.pack_start(canvas, True, True) - #toolbar = NavigationToolbar(canvas, self.window) - #self.vbox.pack_start(toolbar, False, False) + for child in self.vbox.get_children(): + logging.debug('Child available: '+str(child)) - for child in self.vbox.get_children(): - logging.debug('Child available: '+str(child)) + logging.debug('<<') - logging.debug('<<') + def getColor(self, x): + colors=["b","g","r","c","m","y","k", "w"] + if x >= len(colors): + x = x % len(colors) + return colors[x] + + def fmtTableText(self, x, valuesAreTime): + if x <= 0.0001: + return ' ' + elif valuesAreTime: + hour = int(x) + minutes = int((x-hour)*60) + hourLabel = _("h") + minLabel = _("min") + if hour > 0: + return "%d%s %02d%s" % (hour, hourLabel, minutes, minLabel) + else: + return "%02d%s" % (minutes, minLabel) + else: + return '%1.1f' % x - def getColor(self, x): - colors=["b","g","r","c","m","y","k", "w"] - if x >= len(colors): - x = x % len(colors) - return colors[x] - - def fmtTableText(self, x, valuesAreTime): - if x <= 0.0001: - return ' ' - elif valuesAreTime: - hour = int(x) - minutes = int((x-hour)*60) - hourLabel = _("h") - minLabel = _("min") - if hour > 0: - return "%d%s %02d%s" % (hour, hourLabel, minutes, minLabel) - else: - return "%02d%s" % (minutes, minLabel) - else: - return '%1.1f' % x + def drawStackedBars(self,xvalues,yvalues,ylabel,title, valuesAreTime=False): + '''function to draw stacked bars + xvalues needs to be a list of lists of strings, e.g. [0]["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] + yvalues needs to be a list of dicts e.g. [0]{'Kayak': {'Tue': 10.08, 'Fri': 17.579999999999998, 'Thu': 15.66, 'Sat': 30.619999999999997}, {'Run': {'Mon': 9.65, 'Sun': 15.59}} + ''' + #TODO tidy + logging.debug('>>') + logging.debug("Title: %s", (title, )) + logging.debug("X values received: %s", str(xvalues)) + logging.debug("Y values received: %s", str(yvalues)) + self.removeVboxChildren() - def drawStackedBars(self,xvalues,yvalues,ylabel,title, valuesAreTime=False): - '''function to draw stacked bars - xvalues needs to be a list of lists of strings, e.g. [0]["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] - yvalues needs to be a list of dicts e.g. [0]{'Kayak': {'Tue': 10.08, 'Fri': 17.579999999999998, 'Thu': 15.66, 'Sat': 30.619999999999997}, {'Run': {'Mon': 9.65, 'Sun': 15.59}} - ''' - #TODO tidy - logging.debug('>>') - logging.debug("Title: %s", (title, )) - logging.debug("X values received: %s", str(xvalues)) - logging.debug("Y values received: %s", str(yvalues)) - self.removeVboxChildren() + #Check how many axes to draw + if len(xvalues) == 1: #One axis + barWidth = 0.8 + barOffset = 0.1 + elif len(xvalues) == 2: #Twin axes + barWidth = 0.4 + barOffset = 0.1 + else: #Error + return - #Check how many axes to draw - if len(xvalues) == 1: #One axis - barWidth = 0.8 - barOffset = 0.1 - elif len(xvalues) == 2: #Twin axes - barWidth = 0.4 - barOffset = 0.1 - else: #Error - return + keys = yvalues[0].keys() # days of the week + numRows = len(keys) + numCols = len(xvalues[0]) + if numRows == 0: + return + width = .8 + figure = plt.figure(figsize=(6,4), dpi=72) + axis = plt.subplot(111) - keys = yvalues[0].keys() # days of the week - numRows = len(keys) - numCols = len(xvalues[0]) - if numRows == 0: - return - width = .8 - figure = plt.figure(figsize=(6,4), dpi=72) - axis = plt.subplot(111) + ybottoms = [0] * numCols + yheights = [0] * numCols + inds = xrange(0, numCols) + xvals = [x+barOffset for x in range(0, numCols)] + cellText = [] + self.showGraph=False - ybottoms = [0] * numCols - yheights = [0] * numCols - inds = xrange(0, numCols) - xvals = [x+barOffset for x in range(0, numCols)] - cellText = [] - self.showGraph=False + #Display first axis + for key in keys: + logging.debug("Day of the week: %s", str(key)) + for ind in inds: + ybottoms[ind] += yheights[ind] + yheights[ind] = 0 #Zero heights + color = self.getColor(keys.index(key)) + for xvalue in xvalues[0]: + index = xvalues[0].index(xvalue) + if xvalue in yvalues[0][key]: + height = yvalues[0][key][xvalue] + if float(height) > 0.0: + self.showGraph=True + else: + height = self.NEARLY_ZERO + yheights[index] = height + cellText.append([self.fmtTableText(x, valuesAreTime[0]) for x in yheights]) + if self.showGraph: + axis.bar(xvals, yheights, bottom=ybottoms, width=barWidth, color=color, align='edge', label=key) + else: #Only zero results + pass + axis.set_xticklabels('' * len(xvalues[0])) + axis.set_ylabel(ylabel[0]) + if len(xvalues) == 1: + plt.title(title[0]) + axis.legend(loc=0) - #Display first axis - for key in keys: - logging.debug("Day of the week: %s", str(key)) - for ind in inds: - ybottoms[ind] += yheights[ind] - yheights[ind] = 0 #Zero heights - color = self.getColor(keys.index(key)) - for xvalue in xvalues[0]: - index = xvalues[0].index(xvalue) - if xvalue in yvalues[0][key]: - height = yvalues[0][key][xvalue] - if float(height) > 0.0: - self.showGraph=True - else: - height = self.NEARLY_ZERO - yheights[index] = height - cellText.append([self.fmtTableText(x, valuesAreTime[0]) for x in yheights]) - if self.showGraph: - axis.bar(xvals, yheights, bottom=ybottoms, width=barWidth, color=color, align='edge', label=key) - else: #Only zero results - pass - axis.set_xticklabels('' * len(xvalues[0])) - axis.set_ylabel(ylabel[0]) - if len(xvalues) == 1: - plt.title(title[0]) - axis.legend(loc=0) + logging.debug("X values first axis: %s", str(xvals)) + logging.debug("Y values first axis: %s", str(yheights)) - logging.debug("X values first axis: %s", str(xvals)) - logging.debug("Y values first axis: %s", str(yheights)) + #Display twin axis + if len(xvalues) == 2: + self.showGraph=False + ax2 = axis.twinx() + keys = yvalues[1].keys() + ybottoms = [0] * numCols + yheights = [self.NEARLY_ZERO] * numCols + for key in keys: + for ind in inds: + ybottoms[ind] += yheights[ind] + yheights[ind] = 0.0 #Zero heights + color = self.getColor(keys.index(key)) + for xvalue in xvalues[0]: + index = xvalues[0].index(xvalue) + if xvalue in yvalues[1][key]: + height = yvalues[1][key][xvalue] + if float(height) > 0.0: + self.showGraph=True + else: + height = self.NEARLY_ZERO + yheights[index] = height + textToAdd = self.fmtTableText(height, valuesAreTime[1]) + if textToAdd is not ' ': + row = keys.index(key) + col = index + cellText[row][col] += " | %s" % (self.fmtTableText(height, valuesAreTime[1])) + #print "Would add %s to %s %s" % (self.fmtTableText(height, valuesAreTime[1]), index, keys.index(key)) + if self.showGraph: + xvals = [x+barOffset+barWidth for x in range(0, numCols)] + #print "ax2", xvals, yheights, ybottoms + ax2.bar(xvals, yheights, bottom=ybottoms, width=barWidth, color=color, align='edge', label=key) + else: #Only zero results + ax2.bar(xvals, [0]*numCols, bottom=[0]*numCols, width=barWidth, color=color, align='edge', label=key) + pass + ax2.set_xticklabels('' * len(xvalues[1])) + ax2.set_ylabel(ylabel[1]) + ax2.legend(loc=0) + plt.title("%s vs %s" %(title[0],title[1])) - #Display twin axis - if len(xvalues) == 2: - self.showGraph=False - ax2 = axis.twinx() - keys = yvalues[1].keys() - ybottoms = [0] * numCols - yheights = [self.NEARLY_ZERO] * numCols - for key in keys: - for ind in inds: - ybottoms[ind] += yheights[ind] - yheights[ind] = 0.0 #Zero heights - color = self.getColor(keys.index(key)) - for xvalue in xvalues[0]: - index = xvalues[0].index(xvalue) - if xvalue in yvalues[1][key]: - height = yvalues[1][key][xvalue] - if float(height) > 0.0: - self.showGraph=True - else: - height = self.NEARLY_ZERO - yheights[index] = height - textToAdd = self.fmtTableText(height, valuesAreTime[1]) - if textToAdd is not ' ': - row = keys.index(key) - col = index - cellText[row][col] += " | %s" % (self.fmtTableText(height, valuesAreTime[1])) - #print "Would add %s to %s %s" % (self.fmtTableText(height, valuesAreTime[1]), index, keys.index(key)) - if self.showGraph: - xvals = [x+barOffset+barWidth for x in range(0, numCols)] - #print "ax2", xvals, yheights, ybottoms - ax2.bar(xvals, yheights, bottom=ybottoms, width=barWidth, color=color, align='edge', label=key) - else: #Only zero results - ax2.bar(xvals, [0]*numCols, bottom=[0]*numCols, width=barWidth, color=color, align='edge', label=key) - pass - ax2.set_xticklabels('' * len(xvalues[1])) - ax2.set_ylabel(ylabel[1]) - ax2.legend(loc=0) - plt.title("%s vs %s" %(title[0],title[1])) + ## try to do some table stuff + colLabels = xvalues[0] + rowLabels = keys + axis.table(cellText=cellText, cellLoc='center', rowLabels=rowLabels, colLabels=colLabels, loc='bottom') + plt.subplots_adjust(left=0.15,bottom=0.08+(0.03*numRows)) + axis.grid(True) + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea + canvas.show() + self.vbox.pack_start(canvas, True, True) + #toolbar = NavigationToolbar(canvas, self.window) + #self.vbox.pack_start(toolbar, False, False) - ## try to do some table stuff - colLabels = xvalues[0] - rowLabels = keys - axis.table(cellText=cellText, cellLoc='center', rowLabels=rowLabels, colLabels=colLabels, loc='bottom') - plt.subplots_adjust(left=0.15,bottom=0.08+(0.03*numRows)) - axis.grid(True) - canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea - canvas.show() - self.vbox.pack_start(canvas, True, True) - #toolbar = NavigationToolbar(canvas, self.window) - #self.vbox.pack_start(toolbar, False, False) + for child in self.vbox.get_children(): + logging.debug('Child available: '+str(child)) - for child in self.vbox.get_children(): - logging.debug('Child available: '+str(child)) + logging.debug('<<') - logging.debug('<<') + def drawPlot(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None,xzones=None, ylimits=None, y1_linewidth=None): + logging.debug('>>') + logging.debug("Type: plot | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) + logging.debug('xlabel: '+str(xlabel)+' | ylabel: '+str(ylabel)+' | title: '+str(title)) + self.removeVboxChildren() + figure = Figure() + figure.clf() + i = 0 + for value in xvalues: + if i<1: + axis = figure.add_subplot(111) + line = axis.plot(xvalues[i],yvalues[i], color=color[i]) + if y1_linewidth is not None: + line[0].set_linewidth(y1_linewidth) + linewidth = line[0].get_linewidth() + + axis.grid(True) + for tl in axis.get_yticklabels(): + tl.set_color('%s' %color[i]) + #Draw zones on graph, eg for each lap + if xzones is not None: + for xzone in xzones: + if xzones.index(xzone) % 2: + zonecolor='b' + else: + zonecolor='g' + axis.axvspan(xzone[0], xzone[1], alpha=0.25, facecolor=zonecolor) + maxX = max(xvalues[i]) + if i>=1: + ax2 = axis.twinx() + ax2.plot(xvalues[i], yvalues[i], color=color[i]) + for tl in ax2.get_yticklabels(): + tl.set_color('%s' %color[i]) + maxXt = max(xvalues[i]) + if maxXt > maxX: + maxX = maxXt + axis.set_xlabel(xlabel[i]) + i+=1 + axis.set_xlim(0, maxX) - def drawPlot(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None,xzones=None, ylimits=None, y1_linewidth=None): - logging.debug('>>') - logging.debug("Type: plot | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) - logging.debug('xlabel: '+str(xlabel)+' | ylabel: '+str(ylabel)+' | title: '+str(title)) - self.removeVboxChildren() - figure = Figure() - figure.clf() - i = 0 - for value in xvalues: - if i<1: - axis = figure.add_subplot(111) - line = axis.plot(xvalues[i],yvalues[i], color=color[i]) - if y1_linewidth is not None: - line[0].set_linewidth(y1_linewidth) - linewidth = line[0].get_linewidth() - - axis.grid(True) - for tl in axis.get_yticklabels(): - tl.set_color('%s' %color[i]) - #Draw zones on graph, eg for each lap - if xzones is not None: - for xzone in xzones: - if xzones.index(xzone) % 2: - zonecolor='b' - else: - zonecolor='g' - axis.axvspan(xzone[0], xzone[1], alpha=0.25, facecolor=zonecolor) - maxX = max(xvalues[i]) - if i>=1: - ax2 = axis.twinx() - ax2.plot(xvalues[i], yvalues[i], color=color[i]) - for tl in ax2.get_yticklabels(): - tl.set_color('%s' %color[i]) - maxXt = max(xvalues[i]) - if maxXt > maxX: - maxX = maxXt - axis.set_xlabel(xlabel[i]) - i+=1 - axis.set_xlim(0, maxX) + if (len(xvalues)>1): + axis.set_title("%s vs %s" %(ylabel[0],ylabel[1])) + else: + axis.set_title("%s" %(ylabel[0])) - if (len(xvalues)>1): - axis.set_title("%s vs %s" %(ylabel[0],ylabel[1])) - else: - axis.set_title("%s" %(ylabel[0])) + ylim_min, ylim_max = axis.get_ylim() + if ylimits is not None: + logging.debug("Using ylimits: %s" % str(ylimits)) + if ylimits[0] is not None: + ylim_min = ylimits[0] + if ylimits[1] is not None: + ylim_max = ylimits[1] + axis.set_ylim(ylim_min, ylim_max) - ylim_min, ylim_max = axis.get_ylim() - if ylimits is not None: - logging.debug("Using ylimits: %s" % str(ylimits)) - if ylimits[0] is not None: - ylim_min = ylimits[0] - if ylimits[1] is not None: - ylim_max = ylimits[1] - axis.set_ylim(ylim_min, ylim_max) + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea + canvas.show() + self.vbox.pack_start(canvas, True, True) + toolbar = NavigationToolbar(canvas, self.window) + self.vbox.pack_start(toolbar, False, False) + + for child in self.vbox.get_children(): + logging.debug('Child available: '+str(child)) + + logging.debug('<<') + return {'y1_min': ylim_min, 'y1_max': ylim_max, 'y1_linewidth': linewidth} + + def drawPie(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None): + logging.debug('>>') + logging.debug("Type: pie | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) + self.removeVboxChildren() + figure = Figure(figsize=(6,4), dpi=72) + axis = figure.add_subplot(111) - canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea - canvas.show() - self.vbox.pack_start(canvas, True, True) - toolbar = NavigationToolbar(canvas, self.window) - self.vbox.pack_start(toolbar, False, False) - - for child in self.vbox.get_children(): - logging.debug('Child available: '+str(child)) - - logging.debug('<<') - return {'y1_min': ylim_min, 'y1_max': ylim_max, 'y1_linewidth': linewidth} - - def drawPie(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None): - logging.debug('>>') - logging.debug("Type: pie | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) - self.removeVboxChildren() - figure = Figure(figsize=(6,4), dpi=72) - axis = figure.add_subplot(111) + labels = ["rest"] + colors = ["#ffffff"] + frac0 = 0 + frac1 = 0 + frac2 = 0 + frac3 = 0 + frac4 = 0 + frac5 = 0 + for zone in zones: + labels.append(zone[3]) + colors.append(zone[2]) + + for value in yvalues[0]: + if value < zones[4][0]: + frac0+=1 + elif value > zones[4][0] and value < zones[4][1]: + frac1+=1 + elif value > zones[3][0] and value < zones[3][1]: + frac2+=1 + elif value > zones[2][0] and value < zones[2][1]: + frac3+=1 + elif value > zones[1][0] and value < zones[1][1]: + frac4+=1 + elif value > zones[0][0] and value < zones[0][1]: + frac5+=1 + + fracs = [frac0,frac1,frac2,frac3,frac4, frac5] + explode=(0, 0, 0, 0,0,0) + axis.pie(fracs, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True) - labels = ["rest"] - colors = ["#ffffff"] - frac0 = 0 - frac1 = 0 - frac2 = 0 - frac3 = 0 - frac4 = 0 - frac5 = 0 - for zone in zones: - labels.append(zone[3]) - colors.append(zone[2]) - - for value in yvalues[0]: - if value < zones[4][0]: - frac0+=1 - elif value > zones[4][0] and value < zones[4][1]: - frac1+=1 - elif value > zones[3][0] and value < zones[3][1]: - frac2+=1 - elif value > zones[2][0] and value < zones[2][1]: - frac3+=1 - elif value > zones[1][0] and value < zones[1][1]: - frac4+=1 - elif value > zones[0][0] and value < zones[0][1]: - frac5+=1 - - fracs = [frac0,frac1,frac2,frac3,frac4, frac5] - explode=(0, 0, 0, 0,0,0) - axis.pie(fracs, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True) + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea + canvas.show() - canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea - canvas.show() + for child in self.vbox.get_children(): + logging.debug('Child available: '+str(child)) - for child in self.vbox.get_children(): - logging.debug('Child available: '+str(child)) + self.vbox.pack_start(canvas, True, True) + logging.debug('<<') - self.vbox.pack_start(canvas, True, True) - logging.debug('<<') + def drawDefault(self): + logging.debug('>>') + self.axis=self.figure.add_subplot(111) + self.axis.set_xlabel('Yepper') + self.axis.set_ylabel('Flabber') + self.axis.set_title('An Empty Graph') + self.axis.grid(True) + self.canvas.destroy() + self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea + self.canvas.show() + self.vbox.pack_start(self.canvas, True, True) + logging.debug('<<') - def drawDefault(self): - logging.debug('>>') - self.axis=self.figure.add_subplot(111) - self.axis.set_xlabel('Yepper') - self.axis.set_ylabel('Flabber') - self.axis.set_title('An Empty Graph') - self.axis.grid(True) - self.canvas.destroy() - self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea - self.canvas.show() - self.vbox.pack_start(self.canvas, True, True) - logging.debug('<<') + def fill_over(self, ax, x, y, val, color, over=True): + """ + Plot filled x,y for all y over val + if over = False, fill all areas < val + """ + logging.debug('>>') + ybase = asarray(y)-val + crossings = nonzero(less(ybase[:-1] * ybase[1:],0)) - def fill_over(self, ax, x, y, val, color, over=True): - """ - Plot filled x,y for all y over val - if over = False, fill all areas < val - """ - logging.debug('>>') - ybase = asarray(y)-val - crossings = nonzero(less(ybase[:-1] * ybase[1:],0)) + if ybase[0]>=0: + fillon = over + else: + fillon = not over + indLast = 0 + for ind in crossings: + if fillon: + thisX = x[indLast:ind+1] + thisY = y[indLast:ind+1] + thisY[0] = val + thisY[-1] = val + ax.fill(thisX, thisY, color) + fillon = not fillon + indLast = ind + logging.debug('<<') - if ybase[0]>=0: - fillon = over - else: - fillon = not over - indLast = 0 - for ind in crossings: - if fillon: - thisX = x[indLast:ind+1] - thisY = y[indLast:ind+1] - thisY[0] = val - thisY[-1] = val - ax.fill(thisX, thisY, color) - fillon = not fillon - indLast = ind - logging.debug('<<') - - def removeVboxChildren(self): - ''' function to delete vbox children so that multiple graphs do not appear - there must a better way to do this - pyplot? - ''' - logging.debug('>>') - #Tidy up draw areas - vboxChildren = self.vbox.get_children() - logging.debug('Vbox has %d children %s' % (len(vboxChildren), str(vboxChildren) )) - # ToDo: check why vertical container is shared - for child in vboxChildren: - #Remove all FigureCanvasGTK and NavigationToolbar2GTKAgg to stop double ups of graphs - if isinstance(child, matplotlib.backends.backend_gtkagg.FigureCanvasGTK) or isinstance(child, matplotlib.backends.backend_gtkagg.NavigationToolbar2GTKAgg): - logging.debug('Removing child: '+str(child)) - self.vbox.remove(child) - logging.debug('<<') + def removeVboxChildren(self): + ''' function to delete vbox children so that multiple graphs do not appear + there must a better way to do this - pyplot? + ''' + logging.debug('>>') + #Tidy up draw areas + vboxChildren = self.vbox.get_children() + logging.debug('Vbox has %d children %s' % (len(vboxChildren), str(vboxChildren) )) + # ToDo: check why vertical container is shared + for child in vboxChildren: + #Remove all FigureCanvasGTK and NavigationToolbar2GTKAgg to stop double ups of graphs + if isinstance(child, matplotlib.backends.backend_gtkagg.FigureCanvasGTK) or isinstance(child, matplotlib.backends.backend_gtkagg.NavigationToolbar2GTKAgg): + logging.debug('Removing child: '+str(child)) + self.vbox.remove(child) + logging.debug('<<') Modified: pytrainer/trunk/pytrainer/main.py =================================================================== --- pytrainer/trunk/pytrainer/main.py 2010-09-28 03:39:34 UTC (rev 624) +++ pytrainer/trunk/pytrainer/main.py 2010-09-28 21:22:07 UTC (rev 625) @@ -49,7 +49,7 @@ class pyTrainer: def __init__(self,filename = None, data_path = None): #Version constants - self.version ="1.7.2_svn#624" + self.version ="1.7.2_svn#625" self.DB_version = 3 #Process command line options self.startup_options = self.get_options() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |