Example usage for org.jfree.data.xy YIntervalSeriesCollection YIntervalSeriesCollection

List of usage examples for org.jfree.data.xy YIntervalSeriesCollection YIntervalSeriesCollection

Introduction

In this page you can find the example usage for org.jfree.data.xy YIntervalSeriesCollection YIntervalSeriesCollection.

Prototype

public YIntervalSeriesCollection() 

Source Link

Document

Creates a new instance of YIntervalSeriesCollection.

Usage

From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java

private void plotFunction(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape,
        double minX, double maxX) throws ConvertException {
    double[][] points = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX, transformY, minX,
            maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    double[][] functionErrors = null;
    String legend = shortLegend.get(id);
    Color color = colors.get(id);
    Shape shape = shapes.get(id);

    if (showConfidenceInterval) {
        functionErrors = plotable.getFunctionErrors(paramX, paramY, unitX, unitY, transformX, transformY, minX,
                maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    }//  ww  w. j  a  va2 s  .c o m

    if (addInfoInLegend) {
        legend = longLegend.get(id);
    }

    if (color == null) {
        color = defaultColor;
    }

    if (shape == null) {
        shape = defaultShape;
    }

    if (points != null) {
        int i;

        if (plot.getDataset(0) == null) {
            i = 0;
        } else {
            i = plot.getDatasetCount();
        }

        if (functionErrors != null) {
            YIntervalSeriesCollection functionDataset = new YIntervalSeriesCollection();
            DeviationRenderer functionRenderer = new DeviationRenderer(true, false);
            YIntervalSeries series = new YIntervalSeries(legend);

            for (int j = 0; j < points[0].length; j++) {
                double error = Double.isNaN(functionErrors[1][j]) ? 0.0 : functionErrors[1][j];

                series.add(points[0][j], points[1][j], points[1][j] - error, points[1][j] + error);
            }

            functionDataset.addSeries(series);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesFillPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        } else {
            DefaultXYDataset functionDataset = new DefaultXYDataset();
            XYLineAndShapeRenderer functionRenderer = new XYLineAndShapeRenderer(true, false);

            functionDataset.addSeries(legend, points);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        }
    }
}

From source file:de.bund.bfr.knime.pmmlite.views.chart.ChartCreator.java

private List<XYDataset> createStrictFunctionDataSets(Plotable plotable, String id, double minX, double maxX)
        throws ParseException, UnitException {
    List<XYDataset> dataSets = new ArrayList<>();

    for (Map<String, Integer> choiceMap : plotable.getAllChoices(varX.getName())) {
        double[][] modelPoints = plotable.getFunctionPoints(varX, varY, minX, maxX, choiceMap);

        if (modelPoints == null) {
            dataSets.add(null);//from w  w  w  . j a va  2 s  . co  m
            continue;
        }

        double[][] modelErrors = null;

        if (showConfidence || showPrediction) {
            modelErrors = plotable.getFunctionErrors(varX, varY, minX, maxX, showPrediction, choiceMap);
        }

        StringBuilder addLegend = new StringBuilder();

        for (Map.Entry<String, Integer> entry : choiceMap.entrySet()) {
            if (!entry.getKey().equals(varX.getName())) {
                Double value = plotable.getVariables().get(entry.getKey()).get(entry.getValue());

                if (value != null) {
                    String s = NumberFormat.getInstance(Locale.US).format(value);

                    addLegend.append(" (" + entry.getKey() + "=" + s + ")");
                }
            }
        }

        if (modelErrors != null) {
            YIntervalSeriesCollection dataSet = new YIntervalSeriesCollection();
            YIntervalSeries series = new YIntervalSeries(legend.get(id));

            for (int j = 0; j < modelPoints[0].length; j++) {
                double error = Double.isNaN(modelErrors[1][j]) ? 0.0 : modelErrors[1][j];

                series.add(modelPoints[0][j], modelPoints[1][j], modelPoints[1][j] - error,
                        modelPoints[1][j] + error);
            }

            dataSet.addSeries(series);
            dataSets.add(dataSet);
        } else {
            DefaultXYDataset dataSet = new DefaultXYDataset();

            dataSet.addSeries(legend.get(id) + addLegend, modelPoints);

            dataSets.add(dataSet);
        }
    }

    return dataSets;
}

From source file:projects.wdlf47tuc.ProcessAllSwathcal.java

/**
 * Computes the luminosity function for the current boxed region and plots it in a JFrame.
 * Also prints out the coordinates of the selection box vertices and the luminosity function
 * quantities.//  w w  w . java  2  s.co  m
 * 
 * @param sources
 *    The {@link Source}s to compute the luminosity function for.
 */
private void computeAndPlotLuminosityFunction(List<Source> sources) {

    // Print out coordinates of selection box corners
    System.out.println("# Coordinates of selection box corners:");
    System.out.println("# (" + col1Filter + "-" + col2Filter + ")\t" + magFilter);
    for (double[] point : points) {
        System.out.println("# " + point[0] + "\t" + point[1]);
    }
    System.out.println("# Luminosity function:");
    System.out.println("# Mag.\tN\tsigN");

    double magBinWidth = 0.5;

    // Get the range of the data
    double mMin = Double.MAX_VALUE;
    double mMax = -Double.MAX_VALUE;
    for (Source source : sources) {
        double mag = source.getMag(magFilter) - mu;
        mMin = Math.min(mMin, mag);
        mMax = Math.max(mMax, mag);
    }

    // Quantize this to a whole number
    mMin = Math.floor(mMin);
    mMax = Math.ceil(mMax);

    int nBins = (int) Math.rint((mMax - mMin) / magBinWidth);

    // Array to accumulate all objects in each bin
    int[] n = new int[nBins];

    for (Source source : sources) {
        double mag = source.getMag(magFilter) - mu;
        // Bin number
        int bin = (int) Math.floor((mag - mMin) / magBinWidth);
        n[bin]++;
    }

    YIntervalSeries luminosityFunction = new YIntervalSeries("Luminosity Function");

    for (int i = 0; i < nBins; i++) {
        // Bin centre
        double x = mMin + i * magBinWidth + 0.5 * magBinWidth;
        double y = n[i];
        double yErr = n[i] > 0 ? Math.sqrt(y) : 0;
        luminosityFunction.add(x, y, y - yErr, y + yErr);
        System.out.println(x + "\t" + y + "\t" + yErr);
    }

    final YIntervalSeriesCollection data = new YIntervalSeriesCollection();
    data.addSeries(luminosityFunction);

    XYErrorRenderer renderer = new XYErrorRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShape(0, new Ellipse2D.Float(-1f, -1f, 2, 2));
    renderer.setSeriesPaint(0, ChartColor.BLACK);

    NumberAxis xAxis = new NumberAxis("Absolute Magnitude (" + magFilter.toString() + ")");
    xAxis.setAutoRange(true);
    xAxis.setAutoRangeIncludesZero(false);

    NumberAxis yAxis = new NumberAxis("N");
    yAxis.setAutoRange(true);
    yAxis.setAutoRangeIncludesZero(true);

    // Configure plot
    XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinePaint(Color.white);

    // Configure chart
    JFreeChart chart = new JFreeChart("Luminosity Function", xyplot);
    chart.setBackgroundPaint(Color.white);
    chart.setTitle("47 Tuc luminosity function");
    chart.removeLegend();

    final ChartPanel lfChartPanel = new ChartPanel(chart);

    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            JFrame tester = new JFrame();
            tester.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            tester.setLayout(new BorderLayout());
            tester.add(lfChartPanel, BorderLayout.CENTER);
            tester.pack();
            tester.setVisible(true);
        }
    });

}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java

private void plotFunctionSample(XYPlot plot, Plotable plotable, String id, Color defaultColor,
        Shape defaultShape, double minX, double maxX, List<String> warnings) throws ConvertException {
    double[][] functionPoints = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX, transformY,
            minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    double[][] samplePoints;

    if (!inverse) {
        samplePoints = plotable.getFunctionSamplePoints(paramX, paramY, unitX, unitY, transformX, transformY,
                minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, warnings);
    } else {/*from www .  j  ava  2s. c o m*/
        samplePoints = plotable.getInverseFunctionSamplePoints(paramX, paramY, unitX, unitY, transformX,
                transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, warnings);
    }

    double[][] functionErrors = null;
    String legend = shortLegend.get(id);
    Color color = colors.get(id);
    Shape shape = shapes.get(id);

    if (showConfidenceInterval) {
        functionErrors = plotable.getFunctionErrors(paramX, paramY, unitX, unitY, transformX, transformY, minX,
                maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    }

    if (addInfoInLegend) {
        legend = longLegend.get(id);
    }

    if (color == null) {
        color = defaultColor;
    }

    if (shape == null) {
        shape = defaultShape;
    }

    if (functionPoints != null) {
        int i;

        if (plot.getDataset(0) == null) {
            i = 0;
        } else {
            i = plot.getDatasetCount();
        }

        if (functionErrors != null) {
            YIntervalSeriesCollection functionDataset = new YIntervalSeriesCollection();
            DeviationRenderer functionRenderer = new DeviationRenderer(true, false);
            YIntervalSeries series = new YIntervalSeries(legend);

            for (int j = 0; j < functionPoints[0].length; j++) {
                double error = Double.isNaN(functionErrors[1][j]) ? 0.0 : functionErrors[1][j];

                series.add(functionPoints[0][j], functionPoints[1][j], functionPoints[1][j] - error,
                        functionPoints[1][j] + error);
            }

            functionDataset.addSeries(series);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesFillPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            if (samplePoints != null) {
                functionRenderer.setBaseSeriesVisibleInLegend(false);
            }

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        } else {
            DefaultXYDataset functionDataset = new DefaultXYDataset();
            XYLineAndShapeRenderer functionRenderer = new XYLineAndShapeRenderer(true, false);

            functionDataset.addSeries(legend, functionPoints);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            if (samplePoints != null) {
                functionRenderer.setBaseSeriesVisibleInLegend(false);
            }

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        }

        if (samplePoints != null) {
            DefaultXYDataset sampleDataset = new DefaultXYDataset();
            XYLineAndShapeRenderer sampleRenderer = new XYLineAndShapeRenderer(false, true);

            sampleDataset.addSeries(legend, samplePoints);
            sampleRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            sampleRenderer.setSeriesPaint(0, color);
            sampleRenderer.setSeriesShape(0, shape);

            plot.setDataset(i + 1, sampleDataset);
            plot.setRenderer(i + 1, sampleRenderer);
        }
    }
}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java

private void plotBoth(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape,
        double minX, double maxX) throws ConvertException {
    double[][] modelPoints = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX, transformY,
            minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    double[][] dataPoints = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY);
    double[][] functionErrors = null;
    String legend = shortLegend.get(id);
    Color color = colors.get(id);
    Shape shape = shapes.get(id);

    if (showConfidenceInterval) {
        functionErrors = plotable.getFunctionErrors(paramX, paramY, unitX, unitY, transformX, transformY, minX,
                maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    }/*  w  w  w  .  jav a2s.  c  o  m*/

    if (addInfoInLegend) {
        legend = longLegend.get(id);
    }

    if (color == null) {
        color = defaultColor;
    }

    if (shape == null) {
        shape = defaultShape;
    }

    if (modelPoints != null) {
        int i;

        if (plot.getDataset(0) == null) {
            i = 0;
        } else {
            i = plot.getDatasetCount();
        }

        if (functionErrors != null) {
            YIntervalSeriesCollection functionDataset = new YIntervalSeriesCollection();
            DeviationRenderer functionRenderer = new DeviationRenderer(true, false);
            YIntervalSeries series = new YIntervalSeries(legend);

            for (int j = 0; j < modelPoints[0].length; j++) {
                double error = Double.isNaN(functionErrors[1][j]) ? 0.0 : functionErrors[1][j];

                series.add(modelPoints[0][j], modelPoints[1][j], modelPoints[1][j] - error,
                        modelPoints[1][j] + error);
            }

            functionDataset.addSeries(series);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesFillPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            if (dataPoints != null) {
                functionRenderer.setBaseSeriesVisibleInLegend(false);
            }

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        } else {
            DefaultXYDataset functionDataset = new DefaultXYDataset();
            XYLineAndShapeRenderer functionRenderer = new XYLineAndShapeRenderer(true, false);

            functionDataset.addSeries(legend, modelPoints);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            if (dataPoints != null) {
                functionRenderer.setBaseSeriesVisibleInLegend(false);
            }

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        }
    }

    if (dataPoints != null) {
        DefaultXYDataset dataSet = new DefaultXYDataset();
        XYLineAndShapeRenderer dataRenderer = new XYLineAndShapeRenderer(drawLines, true);

        dataSet.addSeries(legend, dataPoints);
        dataRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
        dataRenderer.setSeriesPaint(0, color);
        dataRenderer.setSeriesShape(0, shape);

        int i;

        if (plot.getDataset(0) == null) {
            i = 0;
        } else {
            i = plot.getDatasetCount();
        }

        plot.setDataset(i, dataSet);
        plot.setRenderer(i, dataRenderer);
    }
}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java

private void plotBothStrict(XYPlot plot, Plotable plotable, String id, double minX, double maxX)
        throws ConvertException {
    String legend = shortLegend.get(id);
    List<Color> colorList = colorLists.get(id);
    List<Shape> shapeList = shapeLists.get(id);
    ColorAndShapeCreator creator = new ColorAndShapeCreator(plotable.getNumberOfCombinations());
    int index = 0;

    if (addInfoInLegend) {
        legend = longLegend.get(id);/*from www .j ava  2s  .c  o  m*/
    }

    if (colorList == null || colorList.isEmpty()) {
        colorList = creator.getColorList();
    }

    if (shapeList == null || shapeList.isEmpty()) {
        shapeList = creator.getShapeList();
    }

    for (Map<String, Integer> choiceMap : plotable.getAllChoices()) {
        double[][] dataPoints = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY,
                choiceMap);

        if (dataPoints == null) {
            continue;
        }

        double[][] modelPoints = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX,
                transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, choiceMap);

        if (modelPoints == null) {
            continue;
        }

        double[][] modelErrors = null;

        if (showConfidenceInterval) {
            modelErrors = plotable.getFunctionErrors(paramX, paramY, unitX, unitY, transformX, transformY, minX,
                    maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, choiceMap);
        }

        int i;

        if (plot.getDataset(0) == null) {
            i = 0;
        } else {
            i = plot.getDatasetCount();
        }

        String addLegend = "";

        for (String arg : choiceMap.keySet()) {
            if (!arg.equals(paramX)) {
                addLegend += " (" + arg + "=" + plotable.getFunctionArguments().get(arg).get(choiceMap.get(arg))
                        + ")";
            }
        }

        if (modelErrors != null) {
            YIntervalSeriesCollection modelSet = new YIntervalSeriesCollection();
            DeviationRenderer modelRenderer = new DeviationRenderer(true, false);
            YIntervalSeries series = new YIntervalSeries(legend);

            for (int j = 0; j < modelPoints[0].length; j++) {
                double error = Double.isNaN(modelErrors[1][j]) ? 0.0 : modelErrors[1][j];

                series.add(modelPoints[0][j], modelPoints[1][j], modelPoints[1][j] - error,
                        modelPoints[1][j] + error);
            }

            modelSet.addSeries(series);
            modelRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            modelRenderer.setSeriesPaint(0, colorList.get(index));
            modelRenderer.setSeriesFillPaint(0, colorList.get(index));
            modelRenderer.setSeriesShape(0, shapeList.get(index));

            if (dataPoints != null) {
                modelRenderer.setBaseSeriesVisibleInLegend(false);
            }

            plot.setDataset(i, modelSet);
            plot.setRenderer(i, modelRenderer);
        } else {
            DefaultXYDataset modelSet = new DefaultXYDataset();
            XYLineAndShapeRenderer modelRenderer = new XYLineAndShapeRenderer(true, false);

            modelSet.addSeries(legend + addLegend, modelPoints);
            modelRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            modelRenderer.setBaseSeriesVisibleInLegend(false);
            modelRenderer.setSeriesPaint(0, colorList.get(index));
            modelRenderer.setSeriesShape(0, shapeList.get(index));

            plot.setDataset(i, modelSet);
            plot.setRenderer(i, modelRenderer);
        }

        DefaultXYDataset dataSet = new DefaultXYDataset();
        XYLineAndShapeRenderer dataRenderer = new XYLineAndShapeRenderer(drawLines, true);

        dataSet.addSeries(legend + addLegend, dataPoints);
        dataRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
        dataRenderer.setSeriesPaint(0, colorList.get(index));
        dataRenderer.setSeriesShape(0, shapeList.get(index));
        plot.setDataset(i + 1, dataSet);
        plot.setRenderer(i + 1, dataRenderer);

        index++;
    }
}