def renderGraph(self): # pylint: disable=R0914 aoTable = self._oData.aoTable # # Extract/structure the required data. # aoSeries = list() for j in range(len(aoTable[1].aoValues)): aoSeries.append(list()) asNames = list() oXRange = numpy_arange(self._oData.getGroupCount()) fpMin = self.fpMin fpMax = self.fpMax if self.fpMax is None: fpMax = float(aoTable[1].aoValues[0]) for i in range(1, len(aoTable)): asNames.append(aoTable[i].sName) for j in range(len(aoTable[i].aoValues)): fpValue = float(aoTable[i].aoValues[j]) aoSeries[j].append(fpValue) if fpValue < fpMin: fpMin = fpValue if fpValue > fpMax: fpMax = fpValue fpMid = fpMin + (fpMax - fpMin) / 2.0 if self.cxBarWidth is None: self.cxBarWidth = 1.0 / (len(aoTable[0].asValues) + 1.1) # Render the PNG. oFigure = self._createFigure() oSubPlot = oFigure.add_subplot(1, 1, 1) aoBars = list() for i, _ in enumerate(aoSeries): sColor = self.calcSeriesColor(i) aoBars.append( oSubPlot.bar(oXRange + self.cxBarWidth * i, aoSeries[i], self.cxBarWidth, color=sColor, align='edge')) #oSubPlot.set_title('Title') #oSubPlot.set_xlabel('X-axis') #oSubPlot.set_xticks(oXRange + self.cxBarWidth); oSubPlot.set_xticks(oXRange) oLegend = oSubPlot.legend(aoTable[0].asValues, loc='best', fancybox=True) oLegend.get_frame().set_alpha(0.5) oSubPlot.set_xticklabels(asNames, ha="left") #oSubPlot.set_ylabel('Y-axis') oSubPlot.set_yticks( numpy_arange(fpMin, fpMax + (fpMax - fpMin) / 10 * 0, fpMax / 10)) oSubPlot.grid(True) fpPadding = (fpMax - fpMin) * 0.02 for i, _ in enumerate(aoBars): aoRects = aoBars[i] for j, _ in enumerate(aoRects): oRect = aoRects[j] fpValue = float(aoTable[j + 1].aoValues[i]) if fpValue <= fpMid: oSubPlot.text(oRect.get_x() + oRect.get_width() / 2.0, oRect.get_height() + fpPadding, aoTable[j + 1].asValues[i], ha='center', va='bottom', rotation='vertical', alpha=0.6, fontsize='small') else: oSubPlot.text(oRect.get_x() + oRect.get_width() / 2.0, oRect.get_height() - fpPadding, aoTable[j + 1].asValues[i], ha='center', va='top', rotation='vertical', alpha=0.6, fontsize='small') return self._produceSvg(oFigure)
def renderGraph(self): # pylint: disable=R0914 aoTable = self._oData.aoTable; # # Extract/structure the required data. # aoSeries = list(); for j in range(len(aoTable[1].aoValues)): aoSeries.append(list()); asNames = list(); oXRange = numpy_arange(self._oData.getGroupCount()); fpMin = self.fpMin; fpMax = self.fpMax; if self.fpMax is None: fpMax = float(aoTable[1].aoValues[0]); for i in range(1, len(aoTable)): asNames.append(aoTable[i].sName); for j in range(len(aoTable[i].aoValues)): fpValue = float(aoTable[i].aoValues[j]); aoSeries[j].append(fpValue); if fpValue < fpMin: fpMin = fpValue; if fpValue > fpMax: fpMax = fpValue; fpMid = fpMin + (fpMax - fpMin) / 2.0; if self.cxBarWidth is None: self.cxBarWidth = 1.0 / (len(aoTable[0].asValues) + 1.1); # Render the PNG. oFigure = self._createFigure(); oSubPlot = oFigure.add_subplot(1, 1, 1); aoBars = list(); for i in range(len(aoSeries)): sColor = self.calcSeriesColor(i); aoBars.append(oSubPlot.bar(oXRange + self.cxBarWidth * i, aoSeries[i], self.cxBarWidth, color = sColor, align = 'edge')); #oSubPlot.set_title('Title') #oSubPlot.set_xlabel('X-axis') #oSubPlot.set_xticks(oXRange + self.cxBarWidth); oSubPlot.set_xticks(oXRange); oLegend = oSubPlot.legend(aoTable[0].asValues, loc = 'best', fancybox = True); oLegend.get_frame().set_alpha(0.5); oSubPlot.set_xticklabels(asNames, ha = "left"); #oSubPlot.set_ylabel('Y-axis') oSubPlot.set_yticks(numpy_arange(fpMin, fpMax + (fpMax - fpMin) / 10 * 0, fpMax / 10)); oSubPlot.grid(True); fpPadding = (fpMax - fpMin) * 0.02; for i in range(len(aoBars)): aoRects = aoBars[i] for j in range(len(aoRects)): oRect = aoRects[j]; fpValue = float(aoTable[j + 1].aoValues[i]); if fpValue <= fpMid: oSubPlot.text(oRect.get_x() + oRect.get_width() / 2.0, oRect.get_height() + fpPadding, aoTable[j + 1].asValues[i], ha = 'center', va = 'bottom', rotation = 'vertical', alpha = 0.6, fontsize = 'small'); else: oSubPlot.text(oRect.get_x() + oRect.get_width() / 2.0, oRect.get_height() - fpPadding, aoTable[j + 1].asValues[i], ha = 'center', va = 'top', rotation = 'vertical', alpha = 0.6, fontsize = 'small'); return self._produceSvg(oFigure);