def curve(data, name="", smooth=True, trid=True): """ Creates a curve based on a list of (x,y) tuples. Setting *smooth* to ``True`` results in a spline renderer renderer is used. Setting *trid* to ``True`` results in a 3D plot. In this case the ``smooth`` argument is ignored. """ dataset = XYSeriesCollection() xy = XYSeries(name) for d in data: xy.add(d[0], d[1]) dataset.addSeries(xy) chart = ChartFactory.createXYLineChart(None, None, None, dataset, PlotOrientation.VERTICAL, True, True, False) if smooth: chart.getXYPlot().setRenderer(XYSplineRenderer()) if trid: chart.getXYPlot().setRenderer(XYLine3DRenderer()) return Chart(chart)
def scatterplot(data, name="", xlabel="", ylabel="", size= 3): """ Creates a scatter plot from x,y data. *data* is a list of (x,y) tuples. """ xAxis = NumberAxis(xlabel) xAxis.setAutoRangeIncludesZero(False) yAxis = NumberAxis(ylabel) yAxis.setAutoRangeIncludesZero(False) series = XYSeries("Values"); for (i,j) in data: series.add(i, j) dataset = XYSeriesCollection() dataset.addSeries(series); chart = ChartFactory.createScatterPlot(name, xlabel, ylabel, dataset, PlotOrientation.VERTICAL, True, True, False) plot = chart.getPlot() plot.getRenderer().setSeriesShape(0, ShapeUtilities.createRegularCross(size,size)); return Chart(chart)
def resetData(self, justAnnots=False): if not justAnnots: self.markers = XYSeries("Markers") self.drawCI = False self.chart.getPlot().clearAnnotations() if hasattr(self, 'pv'): del (self.pv) self.updateChartDataset()
def plot2D(points, Ca, Cb): maxIntensity = 255.0 dataset = XYSeriesCollection() seriesNN = XYSeries(channels[Ca+1]+" -ve "+channels[Cb+1]+" -ve") seriesPP = XYSeries(channels[Ca+1]+" +ve "+channels[Cb+1]+" +ve") seriesNP = XYSeries(channels[Ca+1]+" -ve "+channels[Cb+1]+" +ve") seriesPN = XYSeries(channels[Ca+1]+" +ve "+channels[Cb+1]+" -ve") for p in points: posA = channels[Ca+1] in thresholds and p[Ca]>thresholds[ channels[Ca+1] ] posB = channels[Cb+1] in thresholds and p[Cb]>thresholds[ channels[Cb+1] ] if posA and posB: seriesPP.add(p[Cb], p[Ca]) elif posA: seriesPN.add(p[Cb], p[Ca]) elif posB: seriesNP.add(p[Cb], p[Ca]) else: seriesNN.add(p[Cb], p[Ca]) dataset.addSeries(seriesNN) dataset.addSeries(seriesPN) dataset.addSeries(seriesNP) dataset.addSeries(seriesPP) chart = ChartFactory.createScatterPlot( title+" - "+channels[Cb+1]+" vs "+channels[Ca+1], channels[Cb+1], channels[Ca+1], dataset, PlotOrientation.VERTICAL, False,True,False ) plot = chart.getPlot() plot.getDomainAxis().setRange(Range(0.00, maxIntensity), True, False) plot.getRangeAxis().setRange(Range(0.00, maxIntensity), True, False) renderer = chart.getPlot().getRenderer() renderer.setSeriesPaint(0, Color(64,64,64)) #NN renderer.setSeriesPaint(1, Color(0,255,0)) #PN renderer.setSeriesPaint(2, Color(0,0,255)) #NP renderer.setSeriesPaint(3, Color(0,255,255)) #PP shape = Ellipse2D.Float(-1,-1,3,3) renderer.setSeriesShape(0, shape ) renderer.setSeriesShape(1, shape ) renderer.setSeriesShape(2, shape ) renderer.setSeriesShape(3, shape ) frame = ChartFrame(title+" - "+channels[Cb+1]+" vs "+channels[Ca+1], chart) frame.setSize(800, 800) frame.setLocationRelativeTo(None) frame.setVisible(True)
def plot(title, x_label, y_label, *curves): dataset = XYSeriesCollection() for legend, curve in curves: series = XYSeries(legend) for x, y in curve: series.add(x, y) dataset.addSeries(series) chart = ChartFactory.createXYLineChart(title, x_label, y_label, dataset, PlotOrientation.VERTICAL, True, True, False) frame = ChartFrame(title, chart) frame.setVisible(True) frame.setSize(400, 300)
def regression(data, regtype=0): xAxis = NumberAxis("x") xAxis.setAutoRangeIncludesZero(False) yAxis = NumberAxis("y") yAxis.setAutoRangeIncludesZero(False) series = XYSeries("values") xmax = xmin = None for (x, y) in data: series.add(x, y) if xmax is None: xmax = xmin = x else: xmax = max(xmax, x) xmin = min(xmin, x) dataset = XYSeriesCollection() dataset.addSeries(series) renderer1 = XYDotRenderer() plot = XYPlot(dataset, xAxis, yAxis, renderer1) if regtype == 1: coefficients = Regression.getPowerRegression(dataset, 0) curve = PowerFunction2D(coefficients[0], coefficients[1]) regdesc = "Power Regression" else: coefficients = Regression.getOLSRegression(dataset, 0) curve = LineFunction2D(coefficients[0], coefficients[1]) regdesc = "Linear Regression" regressionData = DatasetUtilities.sampleFunction2D( curve, xmin, xmax, 100, "Fitted Regression Line") plot.setDataset(1, regressionData) renderer2 = XYLineAndShapeRenderer(True, False) renderer2.setSeriesPaint(0, Color.blue) plot.setRenderer(1, renderer2) jfchart = JFreeChart(regdesc, JFreeChart.DEFAULT_TITLE_FONT, plot, True) chart = Chart(jfchart) chart.coeffs = coefficients return chart
def xy(data, name='', xlabel='', ylabel=''): """ Creates a xy bar chart. *data* is a list of (x,y) tuples """ series = XYSeries(name) for x, y in data: series.add(x, y) dataset = XYSeriesCollection(series) if len(data) > 1: # hack to set interval width x0, x1 = data[0][0], data[1][0] dataset.setIntervalWidth(x1 - x0) chart = ChartFactory.createXYBarChart(None, xlabel, False, ylabel, dataset, PlotOrientation.VERTICAL, True, True, False) return Chart(chart)
def addSeries(self, series, label=None): if not label: label = "series #" + str(len(self.allSeries) + 1) xySeries = XYSeries(label) iterator = iter(series) t = iterator.next() if isinstance(t, tuple): if len(t) >= 3: raise "Series can have at most two columns" xySeries.add(t[0], t[1]) for t in iterator: xySeries.add(t[0], t[1]) else: xySeries.add(0, t) for i, t in enumerate(iterator): xySeries.add(i, t) self.allSeries.append(xySeries)
def setMarkers(self, markers): self.markers = XYSeries("Markers") self.maxX = 0.0 self.maxY = 0.0 self.minY = -0.05 self.out = [] self.valMarkers = markers for marker in markers: if not marker: continue if marker[0] < 2 and marker[0] > self.maxX: self.maxX = marker[0] if marker[1] < 2 and marker[1] > self.maxY: self.maxY = marker[1] if marker[1] > -2 and marker[1] < self.minY: self.minY = marker[1] #self.markers.add(marker[0], max([0.0, marker[1]])) self.markers.add(marker[0], marker[1]) self.maxX = max([0.501, self.maxX + 0.001]) self.maxX = min([1, self.maxX]) self.maxY += 0.05 self.minY -= 0.05
def getDataSets(self, txName): ''' For a given txNum name, return a set of JFreeChart datasets with data on tx/sec, response times, and bandwidth. ''' logger.debug("getting data sets for " + txName) if self._txNameDatasets == None: logger.warn("Building data sets.") txSecDataset = None # build 'em self._txNameDatasets = {} txNums = self._summaryData.getTxNumNameMap().keys() for txNum in txNums: logger.debug("DEBUG: building DS for " + txNum) dataSetGroup = {} txSecDataset = XYSeriesCollection( ) # not returning a new object bandwidthDataSet = XYSeriesCollection() simpleResponseTimeDataset = XYSeriesCollection() responseTimeDataset = DefaultTableXYDataset() txSecPassSeries = XYSeries("passed") txSecFailSeries = XYSeries("failed") responseTimeSeries = XYSeries("seconds") finishTimeSeries = XYSeries("complete", True, False) resolveHostSeries = XYSeries("resolveHost", True, False) connectSeries = XYSeries("connect", True, False) firstByteSeries = XYSeries("firstByte", True, False) bandwidthSeries = XYSeries("KB/sec") for bucket in self.bucketList: txSecPass = bucket.getTxSecPass(txNum) txSecPassSeries.add(bucket.getStartTime() / 1000.0, txSecPass) txSecFail = bucket.getTxSecFail(txNum) txSecFailSeries.add(bucket.getStartTime() / 1000.0, txSecFail) responseTimeSeries.add(bucket.getStartTime() / 1000.0, bucket.getMeanResponseTime(txNum)) if ga.constants.VORPAL.getPlugin("analyzer").isHTTP(): bandwidthSeries.add( bucket.getStartTime() / 1000.0, bucket.getMeanThroughputKBSec(txNum)) finishTimeSeries.add(bucket.getStartTime() / 1000.0, bucket.getMeanFinishTime(txNum)) resolveHostSeries.add( bucket.getStartTime() / 1000.0, bucket.getMeanResolveHostTime(txNum)) connectSeries.add(bucket.getStartTime() / 1000.0, bucket.getMeanConnectTime(txNum)) firstByteSeries.add(bucket.getStartTime() / 1000.0, bucket.getMeanFirstByteTime(txNum)) txSecDataset.addSeries(txSecPassSeries) txSecDataset.addSeries(txSecFailSeries) responseTimeDataset.addSeries(resolveHostSeries) responseTimeDataset.addSeries(connectSeries) responseTimeDataset.addSeries(firstByteSeries) responseTimeDataset.addSeries(finishTimeSeries) simpleResponseTimeDataset.addSeries(responseTimeSeries) bandwidthDataSet.addSeries(bandwidthSeries) dataSetGroup[TX_SEC_KEY] = txSecDataset dataSetGroup[FULL_RESPONSE_TIME_KEY] = responseTimeDataset dataSetGroup[THROUGHPUT_KEY] = bandwidthDataSet dataSetGroup[ SIMPLE_RESPONSE_TIME_KEY] = simpleResponseTimeDataset self._txNameDatasets[txNum] = dataSetGroup logger.debug("DEBUG: done building data sets.") return self._txNameDatasets[txName]