Beispiel #1
0
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)
    
Beispiel #2
0
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
Beispiel #3
0
    def _overlay(self, chart):
        plot = self.chart.getPlot()
        plot.setDataset(self.datasets, chart.chart.getPlot().getDataset())
        plot.setRenderer(self.datasets, chart.chart.getPlot().getRenderer())
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD)

        yAxis = NumberAxis("")
        plot.setRangeAxis(self.datasets, yAxis)
        plot.mapDatasetToRangeAxis(self.datasets, self.datasets)
        self.datasets += 1