Ejemplo n.º 1
0
  private static JFreeChart createChart(XYZDataset xyzdataset) {
    JFreeChart jfreechart =
        ChartFactory.createBubbleChart(
            "AGE vs WEIGHT vs WORK",
            "Weight (kg)",
            "AGE",
            xyzdataset,
            PlotOrientation.HORIZONTAL,
            true,
            true,
            false);

    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setForegroundAlpha(0.65F);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.blue);
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setLowerMargin(0.2);
    numberaxis.setUpperMargin(0.5);
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setLowerMargin(0.8);
    numberaxis1.setUpperMargin(0.9);

    return jfreechart;
  }
  private JFreeChart createChart(XYZDataset xyzDataSet) {
    NumberAxis numberAxis = new NumberAxis("X");
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberAxis.setLowerMargin(0.0D);
    numberAxis.setUpperMargin(0.0D);
    numberAxis.setAxisLinePaint(Color.white);
    numberAxis.setTickMarkPaint(Color.white);

    NumberAxis numberAxis1 = new NumberAxis("Y");
    numberAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberAxis1.setLowerMargin(0.0D);
    numberAxis1.setUpperMargin(0.0D);
    numberAxis1.setAxisLinePaint(Color.white);
    numberAxis1.setTickMarkPaint(Color.white);

    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    PaintScale paintScale;
    if (this.type == MarkovDataDialog.HeatMapType.COMPARISON)
      paintScale = createNewLookupPaintScale();
    else paintScale = new GrayPaintScale();

    //        paintScale.add(-1.0,Color.WHITE );
    xyblockrenderer.setPaintScale(paintScale);

    XYPlot xyplot = new XYPlot(xyzDataSet, numberAxis, numberAxis1, xyblockrenderer);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setOutlinePaint(Color.blue);

    JFreeChart jfreechart = new JFreeChart("heat map", xyplot);
    jfreechart.removeLegend();

    NumberAxis numberAxis2 = new NumberAxis("Scale");
    numberAxis2.setAxisLinePaint(Color.white);
    numberAxis2.setTickMarkPaint(Color.white);
    numberAxis2.setRange(-1.0D, 1.0D);
    numberAxis2.setTickLabelFont(new Font("Dialog", 0, 7));
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(paintScale, numberAxis2);
    paintscalelegend.setStripOutlineVisible(false);
    paintscalelegend.setSubdivisionCount(20);
    paintscalelegend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    paintscalelegend.setAxisOffset(5D);
    paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D));
    //        paintscalelegend.setFrame(new BlockBorder(Color.red));
    paintscalelegend.setPadding(new RectangleInsets(10D, 10D, 10D, 10D));
    paintscalelegend.setStripWidth(10D);
    paintscalelegend.setPosition(RectangleEdge.LEFT);
    jfreechart.addSubtitle(paintscalelegend);
    //        ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
  }
Ejemplo n.º 3
0
  private JFreeChart createScatChart(
      BufferedImage image, PaintScale ps, int plotWidth, int plotHeigh) {
    JFreeChart chart_temp =
        ChartFactory.createScatterPlot(
            null,
            null,
            null,
            new XYSeriesCollection(),
            PlotOrientation.VERTICAL,
            false,
            false,
            false);
    chart_temp.getXYPlot().getRangeAxis().setInverted(true);
    chart_temp.setBackgroundPaint(JFreeChart.DEFAULT_BACKGROUND_PAINT);
    XYDataImageAnnotation ann = new XYDataImageAnnotation(image, 0, 0, plotWidth, plotHeigh, true);
    XYPlot plot = (XYPlot) chart_temp.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.getRenderer().addAnnotation(ann, Layer.BACKGROUND);
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    xAxis.setVisible(false);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setVisible(false);

    NumberAxis scaleAxis = new NumberAxis();
    scaleAxis.setAxisLinePaint(Color.black);
    scaleAxis.setTickMarkPaint(Color.black);
    scaleAxis.setRange(ps.getLowerBound(), ps.getUpperBound());
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 9));
    PaintScaleLegend legend = new PaintScaleLegend(ps, scaleAxis);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.RIGHT);
    legend.setBackgroundPaint(chart_temp.getBackgroundPaint());
    chart_temp.addSubtitle(legend);

    return chart_temp;
  }
  public void createChart() {

    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report =
        ChartFactory.createStackedBarChart(
            this.datasetStrategy.getTitle(),
            this.datasetStrategy.getYAxisLabel(),
            this.datasetStrategy.getXAxisLabel(),
            categorydataset,
            PlotOrientation.HORIZONTAL,
            true,
            true,
            false);
    // report.setBackgroundPaint( Color.lightGray );
    report.setAntiAlias(false);
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CloverBarChartStrategy
        || datasetStrategy instanceof MultiCloverBarChartStrategy) {
      numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE);
      numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setItemLabelsVisible(true);
    stackedbarrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setItemLabelFont(
        StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD));
    int height =
        (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2)
            + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT
            + 10;
    if (height > ChartUtils.MINIMUM_HEIGHT) {
      super.setHeight(height);
    } else {
      super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
      stackedbarrenderer.setSeriesPaint(i, paints[i]);
    }
  }
  @Override
  public JFreeChart draw(List<ExperimentInfo> exps) {
    List<Integer> firstLayer = new ArrayList<>();
    List<Integer> secondLayer = new ArrayList<>();
    List<Double> performances = new ArrayList<>();

    exps.stream()
        .filter(e -> e.hasResults())
        .forEach(
            e -> {
              List<Integer> layers = e.getLayerTopology();
              assert (layers.size() == 1 || layers.size() == 2);

              firstLayer.add(layers.get(0));

              if (layers.size() == 2) secondLayer.add(layers.get(1));
              else secondLayer.add(0);

              performances.add(e.getResults().getPerformance());
            });

    assert (firstLayer.size() == secondLayer.size() && secondLayer.size() == performances.size());

    double[] xvalues = new double[firstLayer.size()];
    double[] yvalues = new double[secondLayer.size()];
    double[] zvalues = new double[performances.size()];
    for (int i = 0; i < firstLayer.size(); i++) {
      xvalues[i] = firstLayer.get(i);
      yvalues[i] = secondLayer.get(i);
      zvalues[i] = performances.get(i);
    }

    DefaultXYZDataset dataset = new DefaultXYZDataset();

    dataset.addSeries("aaaa", new double[][] {xvalues, yvalues, zvalues});

    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);

    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);

    XYBlockRenderer renderer = new XYBlockRenderer();

    PaintScale scale =
        new GrayPaintScale(
            performances.stream().mapToDouble(d -> d).min().getAsDouble(),
            performances.stream().mapToDouble(d -> d).max().getAsDouble());
    renderer.setPaintScale(scale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);

    JFreeChart chart = new JFreeChart("XYBlockChartDemo1", plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    return chart;
  }
Ejemplo n.º 6
0
  private JFreeChart display(
      String title, int height, int width, String category, List<Report> toolResults) {

    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // averages
    ArrayList<Double> averageFalseRates = new ArrayList<Double>();

    ArrayList<Double> averageTrueRates = new ArrayList<Double>();
    double averageFalseRate = 0;
    double averageTrueRate = 0;

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries("Scores");
    for (int i = 0; i < toolResults.size(); i++) {
      Report toolReport = toolResults.get(i);
      OverallResult overallResults = toolReport.getOverallResults().getResults(category);
      series.add(
          overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100);
      if (toolReport.isCommercial()) {
        averageFalseRates.add(overallResults.getFalsePositiveRate());

        averageTrueRates.add(overallResults.getTruePositiveRate());
      }
    }

    for (double d : averageFalseRates) {
      averageFalseRate += d;
    }
    averageFalseRate = averageFalseRate / averageFalseRates.size();

    for (double d : averageTrueRates) {
      averageTrueRate += d;
    }
    averageTrueRate = averageTrueRate / averageTrueRates.size();

    series.add(averageFalseRate * 100, averageTrueRate * 100);
    dataset.addSeries(series);
    afr = averageFalseRate;
    atr = averageTrueRate;

    chart =
        ChartFactory.createScatterPlot(
            title,
            "False Positive Rate",
            "True Positive Rate",
            dataset,
            PlotOrientation.VERTICAL,
            true,
            true,
            false);
    String fontName = "Arial";
    DecimalFormat pctFormat = new DecimalFormat("0'%'");

    theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title
    theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 16));
    theme.setSmallFont(new Font(fontName, Font.PLAIN, 12));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);

    XYPlot xyplot = chart.getXYPlot();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();

    xyplot.setOutlineVisible(true);

    rangeAxis.setRange(-5, 109.99);
    rangeAxis.setNumberFormatOverride(pctFormat);
    rangeAxis.setTickLabelPaint(Color.decode("#666666"));
    rangeAxis.setMinorTickCount(5);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setMinorTickMarksVisible(true);
    rangeAxis.setTickMarksVisible(true);
    rangeAxis.setLowerMargin(10);
    rangeAxis.setUpperMargin(10);
    xyplot.setRangeGridlineStroke(new BasicStroke());
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setRangeMinorGridlinesVisible(true);

    domainAxis.setRange(-5, 105);
    domainAxis.setNumberFormatOverride(pctFormat);
    domainAxis.setTickLabelPaint(Color.decode("#666666"));
    domainAxis.setMinorTickCount(5);
    domainAxis.setTickUnit(new NumberTickUnit(10));
    domainAxis.setAxisLineVisible(true);
    domainAxis.setTickMarksVisible(true);
    domainAxis.setMinorTickMarksVisible(true);
    domainAxis.setLowerMargin(10);
    domainAxis.setUpperMargin(10);
    xyplot.setDomainGridlineStroke(new BasicStroke());
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setDomainMinorGridlinesVisible(true);

    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
    chart.removeLegend();
    chart.setPadding(new RectangleInsets(20, 20, 20, 20));
    xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7"));

    //        // setup item labels
    //        XYItemRenderer renderer = xyplot.getRenderer();
    //        Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f);
    //        for ( int i = 0; i < dataset.getSeriesCount(); i++ ) {
    //            renderer.setSeriesShape(i, circle);
    //            renderer.setSeriesPaint(i, Color.blue);
    //            String label = ""+((String)dataset.getSeries(i).getKey());
    //            int idx = label.indexOf( ':');
    //            label = label.substring( 0, idx );
    //            StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(label);
    //            renderer.setSeriesItemLabelGenerator(i, generator);
    //            renderer.setSeriesItemLabelsVisible(i, true);
    //            ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
    // TextAnchor.BASELINE_CENTER );
    //            renderer.setSeriesPositiveItemLabelPosition(i, position);
    //        }

    makeDataLabels(category, toolResults, xyplot);
    makeLegend(category, toolResults, 57, 48, dataset, xyplot);

    Stroke dashed =
        new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {6, 3}, 0);
    for (XYDataItem item : (List<XYDataItem>) series.getItems()) {
      double x = item.getX().doubleValue();
      double y = item.getY().doubleValue();
      double z = (x + y) / 2;
      XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue);
      xyplot.addAnnotation(score);
    }

    //        // put legend inside plot
    //        LegendTitle lt = new LegendTitle(xyplot);
    //        lt.setItemFont(theme.getSmallFont());
    //        lt.setPosition(RectangleEdge.RIGHT);
    //        lt.setItemFont(theme.getSmallFont());
    //        XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT);
    //        ta.setMaxWidth(0.48);
    //        xyplot.addAnnotation(ta);

    // draw guessing line
    XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red);
    xyplot.addAnnotation(guessing);

    XYPointerAnnotation worse =
        makePointer(75, 5, "Worse than guessing", TextAnchor.TOP_CENTER, 90);
    xyplot.addAnnotation(worse);

    XYPointerAnnotation better =
        makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270);
    xyplot.addAnnotation(better);

    XYTextAnnotation stroketext =
        new XYTextAnnotation("                     Random Guess", 88, 107);
    stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT);
    stroketext.setBackgroundPaint(Color.white);
    stroketext.setPaint(Color.red);
    stroketext.setFont(theme.getRegularFont());
    xyplot.addAnnotation(stroketext);

    XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.addAnnotation(strokekey);

    ChartPanel cp =
        new ChartPanel(
            chart, height, width, 400, 400, 1200, 1200, false, false, false, false, false, false);
    f.add(cp);
    f.pack();
    f.setLocationRelativeTo(null);
    //      f.setVisible(true);

    return chart;
  }