List of usage examples for org.jfree.data.function Function2D Function2D
Function2D
From source file:ec.ui.view.DistributionView.java
protected void onDataChange() { XYPlot plot = chartPanel.getChart().getXYPlot(); if (data != DEFAULT_DATA) { DescriptiveStatistics stats = new DescriptiveStatistics(new DataBlock(data)); double m = 0, M = 0, dv = 1; if (adjustDistribution && distribution != DEFAULT_DISTRIBUTION) { m = stats.getAverage();/* w ww . jav a2 s.co m*/ M = distribution.getExpectation(); double v = stats.getVar(); double V = distribution.getVariance(); dv = Math.sqrt(v / V); } final double xmin = stats.getMin() < lBound ? stats.getMin() : lBound; final double xmax = stats.getMax() > rBound ? stats.getMax() : rBound; final int n = hCount != 0 ? hCount : (int) Math.ceil(Math.sqrt(stats.getObservationsCount())); final double xstep = (xmax - xmin) / n; // distribution > if (distribution != DEFAULT_DISTRIBUTION) { Function2D density = new Function2D() { @Override public double getValue(double x) { return distribution.getDensity(x); } }; final double zmin = distribution.hasLeftBound() != BoundaryType.None ? distribution.getLeftBound() : ((xmin - xstep - m) / dv + M); final double zmax = distribution.hasRightBound() != BoundaryType.None ? distribution.getRightBound() : ((xmax + xstep - m) / dv + M); // TODO: create IDistribution#getName() method String name = distribution.getClass().getSimpleName(); ((XYLineAndShapeRenderer) plot.getRenderer(DISTRIBUTION_INDEX)) .setLegendItemToolTipGenerator(getTooltipGenerator(distribution)); plot.setDataset(DISTRIBUTION_INDEX, DatasetUtilities.sampleFunction2D(density, zmin, zmax, n, name)); } else { plot.setDataset(DISTRIBUTION_INDEX, Charts.emptyXYDataset()); } // < distribution // histogram > XYSeries hSeries = new XYSeries(""); double nobs = stats.getObservationsCount(); for (int i = 0; i <= n; ++i) { double x0 = xmin + i * xstep; double x1 = x0 + xstep; double y = stats.countBetween(x0, x1) / (nobs * xstep / dv); hSeries.add(((x0 + x1) / 2 - m) / dv + M, y); } plot.setDataset(HISTOGRAM_INDEX, new XYBarDataset(new XYSeriesCollection(hSeries), xstep / dv + M)); // < histogram } else { plot.setDataset(HISTOGRAM_INDEX, Charts.emptyXYDataset()); plot.setDataset(DISTRIBUTION_INDEX, Charts.emptyXYDataset()); } onColorSchemeChange(); }
From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java
private XYIntervalSeries computeAcceptableDeviationData(double lowerBound, double upperBound) { final Function2D identityFunction = new Function2D() { @Override/* w ww .j a v a 2 s . c o m*/ public double getValue(double x) { return x; } }; final XYSeries identity = DatasetUtilities.sampleFunction2DToSeries(identityFunction, lowerBound, upperBound, 100, "1:1 line"); final XYIntervalSeries xyIntervalSeries = new XYIntervalSeries(identity.getKey()); final List<XYDataItem> items = identity.getItems(); for (XYDataItem item : items) { final double x = item.getXValue(); final double y = item.getYValue(); if (scatterPlotModel.showAcceptableDeviation) { final double acceptableDeviation = scatterPlotModel.acceptableDeviationInterval; final double xOff = acceptableDeviation * x / 100; final double yOff = acceptableDeviation * y / 100; xyIntervalSeries.add(x, x - xOff, x + xOff, y, y - yOff, y + yOff); } else { xyIntervalSeries.add(x, x, x, y, y, y); } } return xyIntervalSeries; }