List of usage examples for org.jfree.data.general DatasetUtilities sampleFunction2D
public static XYDataset sampleFunction2D(Function2D f, double start, double end, int samples, Comparable seriesKey)
From source file:org.jfree.chart.demo.NormalDistributionDemo1.java
public static XYDataset createDataset() { NormalDistributionFunction2D normaldistributionfunction2d = new NormalDistributionFunction2D(0.0D, 1.0D); XYDataset xydataset = DatasetUtilities.sampleFunction2D(normaldistributionfunction2d, -5D, 5D, 100, "Normal"); return xydataset; }
From source file:org.jfree.chart.demo.Function2DDemo1.java
public static XYDataset createDataset() { XYDataset xydataset = DatasetUtilities.sampleFunction2D(new X2(), -4D, 4D, 40, "f(x)"); return xydataset; }
From source file:org.jfree.chart.demo.NormalDistributionDemo.java
/** * A demonstration application showing a normal distribution. * * @param title the frame title./*from w ww . j ava2s.c om*/ */ public NormalDistributionDemo(final String title) { super(title); Function2D normal = new NormalDistributionFunction2D(0.0, 1.0); XYDataset dataset = DatasetUtilities.sampleFunction2D(normal, -5.0, 5.0, 100, "Normal"); final JFreeChart chart = ChartFactory.createXYLineChart("XY Series Demo", "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:edu.ucla.stat.SOCR.chart.demo.NormalDistributionDemo.java
/** * Creates a dataset with sample values from the normal distribution * function.//from w w w . j ava2 s . c om * @param isDemo true use the demo data, false use data from the JTable * @return A dataset. */ protected XYDataset createDataset(boolean isDemo) { if (isDemo) { mean = 0.0; stdDev = 1.0; Function2D normal = new NormalDistributionFunction2D(mean, stdDev); XYDataset dataset = DatasetUtilities.sampleFunction2D(normal, -10.0, 10.0, 100, "Normal"); return dataset; } else { setArrayFromTable(); String[][] x = new String[xyLength][independentVarLength]; double[][] y = new double[xyLength][dependentVarLength]; for (int index = 0; index < independentVarLength; index++) for (int i = 0; i < xyLength; i++) x[i][index] = indepValues[i][index]; for (int index = 0; index < dependentVarLength; index++) for (int i = 0; i < xyLength; i++) { if (depValues[i][index] != null) y[i][index] = Double.parseDouble(depValues[i][index]); } mean = Double.parseDouble(x[0][0]); stdDev = y[0][0]; Function2D normal = new NormalDistributionFunction2D(mean, stdDev); XYDataset dataset = DatasetUtilities.sampleFunction2D(normal, -10.0, 10.0, 100, "Normal"); return dataset; } }
From source file:org.datacleaner.widgets.result.NumberAnalyzerResultSwingRenderer.java
@Override protected void decorate(NumberAnalyzerResult result, DCTable table, final DisplayChartCallback displayChartCallback) { // find the std. deviation row number. int rowNumber = -1; {/*from w w w .jav a2s.c om*/ for (int i = 0; i < table.getRowCount(); i++) { Object value = table.getValueAt(i, 0); if (NumberAnalyzer.MEASURE_STANDARD_DEVIATION.equals(value)) { rowNumber = i; break; } } if (rowNumber == -1) { throw new IllegalStateException("Could not determine Std. deviation row number!"); } } Crosstab<?> crosstab = result.getCrosstab(); final InputColumn<? extends Number>[] columns = result.getColumns(); int columnNumber = 1; for (final InputColumn<? extends Number> column : columns) { final CrosstabNavigator<?> nav = crosstab.where(NumberAnalyzer.DIMENSION_COLUMN, column.getName()); final Number numRows = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_ROW_COUNT).get(); if (numRows.intValue() > 0) { final Number standardDeviation = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_STANDARD_DEVIATION).get(); if (standardDeviation != null) { ActionListener action = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final Number mean = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_MEAN).get(); final Number min = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_LOWEST_VALUE) .get(); final Number max = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_HIGHEST_VALUE) .get(); final NormalDistributionFunction2D normalDistributionFunction = new NormalDistributionFunction2D( mean.doubleValue(), standardDeviation.doubleValue()); final XYDataset dataset = DatasetUtilities.sampleFunction2D(normalDistributionFunction, min.doubleValue(), max.doubleValue(), 100, "Normal"); final JFreeChart chart = ChartFactory.createXYLineChart( "Normal distribution of " + column.getName(), column.getName(), "", dataset, PlotOrientation.VERTICAL, false, true, false); ChartUtils.applyStyles(chart); Marker meanMarker = new ValueMarker(mean.doubleValue(), WidgetUtils.BG_COLOR_BLUE_DARK, new BasicStroke(2f)); meanMarker.setLabel("Mean"); meanMarker.setLabelOffset(new RectangleInsets(70d, 25d, 0d, 0d)); meanMarker.setLabelFont(WidgetUtils.FONT_SMALL); chart.getXYPlot().addDomainMarker(meanMarker); final ChartPanel chartPanel = ChartUtils.createPanel(chart, true); displayChartCallback.displayChart(chartPanel); } }; DCPanel panel = AbstractCrosstabResultSwingRenderer.createActionableValuePanel( standardDeviation, Alignment.RIGHT, action, IconUtils.CHART_LINE); table.setValueAt(panel, rowNumber, columnNumber); } } columnNumber++; } super.decorate(result, table, displayChartCallback); }
From source file:org.eobjects.datacleaner.widgets.result.NumberAnalyzerResultSwingRenderer.java
@Override protected void decorate(NumberAnalyzerResult result, DCTable table, final DisplayChartCallback displayChartCallback) { // find the std. deviation row number. int rowNumber = -1; {/* ww w . j av a 2 s . c o m*/ for (int i = 0; i < table.getRowCount(); i++) { Object value = table.getValueAt(i, 0); if (NumberAnalyzer.MEASURE_STANDARD_DEVIATION.equals(value)) { rowNumber = i; break; } } if (rowNumber == -1) { throw new IllegalStateException("Could not determine Std. deviation row number!"); } } Crosstab<?> crosstab = result.getCrosstab(); final InputColumn<? extends Number>[] columns = result.getColumns(); int columnNumber = 1; for (final InputColumn<? extends Number> column : columns) { final CrosstabNavigator<?> nav = crosstab.where(NumberAnalyzer.DIMENSION_COLUMN, column.getName()); final Number numRows = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_ROW_COUNT).get(); if (numRows.intValue() > 0) { final Number standardDeviation = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_STANDARD_DEVIATION).get(); if (standardDeviation != null) { ActionListener action = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final Number mean = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_MEAN).get(); final Number min = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_LOWEST_VALUE) .get(); final Number max = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_HIGHEST_VALUE) .get(); final NormalDistributionFunction2D normalDistributionFunction = new NormalDistributionFunction2D( mean.doubleValue(), standardDeviation.doubleValue()); final XYDataset dataset = DatasetUtilities.sampleFunction2D(normalDistributionFunction, min.doubleValue(), max.doubleValue(), 100, "Normal"); final JFreeChart chart = ChartFactory.createXYLineChart( "Normal distribution of " + column.getName(), column.getName(), "", dataset, PlotOrientation.VERTICAL, false, true, false); ChartUtils.applyStyles(chart); Marker meanMarker = new ValueMarker(mean.doubleValue(), WidgetUtils.BG_COLOR_BLUE_DARK, new BasicStroke(2f)); meanMarker.setLabel("Mean"); meanMarker.setLabelOffset(new RectangleInsets(70d, 25d, 0d, 0d)); meanMarker.setLabelFont(WidgetUtils.FONT_SMALL); chart.getXYPlot().addDomainMarker(meanMarker); final ChartPanel chartPanel = new ChartPanel(chart); displayChartCallback.displayChart(chartPanel); } }; DCPanel panel = AbstractCrosstabResultSwingRenderer.createActionableValuePanel( standardDeviation, Alignment.RIGHT, action, "images/chart-types/line.png"); table.setValueAt(panel, rowNumber, columnNumber); } } columnNumber++; } super.decorate(result, table, displayChartCallback); }
From source file:MainClass.EquationSolver.java
@Override public void actionPerformed(ActionEvent e) { this.setVisible(true); textArea.setText(null);//command to clear the textArea String decString = "0.";//block used to set the decimal point if (decTextField.getText().hashCode() != 0) { for (int i = 0; i < (Integer.parseInt(decTextField.getText())); i++) { decString += "0"; }/* w w w.j a v a 2 s. c o m*/ decString += "1"; decpoint = Double.parseDouble(decString); } else { decTextField.setText("0"); } switch (methodComboBox.getSelectedItem().toString()) {//block used to show or hide the second textField coresponding the mothod selected case "Secant": sp2TextField.setVisible(true); this.setVisible(true); break; case "Bisection": sp2TextField.setVisible(true); this.setVisible(true); break; default: sp2TextField.setVisible(false); this.setVisible(true); break; } if (e.getSource() == calculateBtn) { try {//Try used to test if the inserted starting point is not a numerical value switch (methodComboBox.getSelectedItem().toString()) {//Switch used to implement the limits of the function ploted on the graph accordingly the method selected case "Secant": case "Bisection": if (sp1TextField.getText().hashCode() == 0 || sp2TextField.getText().hashCode() == 0) { JOptionPane.showMessageDialog(null, "Please insert two starting points"); } if (Double.parseDouble(sp2TextField.getText()) > Double.parseDouble(sp1TextField.getText())) { limitx = Math.abs(Double.parseDouble(sp2TextField.getText())); limity = limitx * (-1); } else { limitx = Math.abs(Double.parseDouble(sp1TextField.getText())); limity = limitx * (-1); } break; case "Newton-Raphson": limitx = Math.abs(Double.parseDouble(sp1TextField.getText())); limity = limitx * (-1); break; case "Select a method:": JOptionPane.showMessageDialog(null, "Please select a method!"); break; default: limitx = 50; limity = -50; break; } if (limitx == 0) { limitx = 50; limity = -50; } else if ("ln(x+1)+1".equals(equationComboBox.getSelectedItem().toString()) || "e^x-3x".equals(equationComboBox.getSelectedItem().toString()) || "x-x^2".equals(equationComboBox.getSelectedItem().toString())) { limitx *= 10; limity *= 10; } if (null != equationComboBox.getSelectedItem().toString()) {//Test if the comboBox was pressed switch (equationComboBox.getSelectedItem().toString()) {//Swith implementing in a global variable a dataset accordingly the function selected case "x-x^2": datasetFunction = DatasetUtilities.sampleFunction2D(v -> v - Math.pow(v, 2.0), limity, limitx, 100, "Function x-x^2"); break; case "ln(x+1)+1": datasetFunction = DatasetUtilities.sampleFunction2D(v -> Math.log(v + 1.0) + 1.0, limity, limitx, 100, "Function ln(x+1)+1"); break; default: datasetFunction = DatasetUtilities.sampleFunction2D(v -> (Math.exp(v)) - (3 * v), limity, limitx, 100, "Function e^x-3x"); break; } } switch (equationComboBox.getSelectedItem().toString()) {// Switch used to verify what function and method was selected case "x-x^2": if (null != methodComboBox.getSelectedItem().toString()) { switch (methodComboBox.getSelectedItem().toString()) { case "Newton-Raphson": CalculusNewtonRaphson.newtonRaphson1(Double.parseDouble(sp1TextField.getText()), decpoint); refreshTable(CalculusNewtonRaphson.createChartNewtonRapson(datasetFunction)); textArea.append(CalculusNewtonRaphson .textDataNewtonRapson(Integer.parseInt(decTextField.getText()))); table.setModel(CalculusNewtonRaphson.getTableData()); break; case "Secant": CalculusSecant.secant1(Double.parseDouble(sp1TextField.getText()), Double.parseDouble(sp2TextField.getText()), decpoint); refreshTable(CalculusSecant.createChartSecant(datasetFunction)); textArea.append( CalculusSecant.textDataSecant(Integer.parseInt(decTextField.getText()))); table.setModel(CalculusSecant.getTableData()); break; case "Bisection": CalculusBisection.bisection1(Double.parseDouble(sp1TextField.getText()), Double.parseDouble(sp2TextField.getText()), decpoint); refreshTable(CalculusBisection.createChartBisection(datasetFunction)); textArea.append( CalculusBisection.textDataBisection(Integer.parseInt(decTextField.getText()))); table.setModel(CalculusBisection.getTableData()); break; } } break; case "ln(x+1)+1": if (null != methodComboBox.getSelectedItem().toString()) { switch (methodComboBox.getSelectedItem().toString()) { case "Newton-Raphson": CalculusNewtonRaphson.newtonRaphson2(Double.parseDouble(sp1TextField.getText()), decpoint); refreshTable(CalculusNewtonRaphson.createChartNewtonRapson(datasetFunction)); textArea.append(CalculusNewtonRaphson .textDataNewtonRapson(Integer.parseInt(decTextField.getText()))); table.setModel(CalculusNewtonRaphson.getTableData()); break; case "Secant": CalculusSecant.secant2(Double.parseDouble(sp1TextField.getText()), Double.parseDouble(sp2TextField.getText()), decpoint); refreshTable(CalculusSecant.createChartSecant(datasetFunction)); textArea.append( CalculusSecant.textDataSecant(Integer.parseInt(decTextField.getText()))); table.setModel(CalculusSecant.getTableData()); break; case "Bisection": CalculusBisection.bisection2(Double.parseDouble(sp1TextField.getText()), Double.parseDouble(sp2TextField.getText()), decpoint); refreshTable(CalculusBisection.createChartBisection(datasetFunction)); textArea.append( CalculusBisection.textDataBisection(Integer.parseInt(decTextField.getText()))); table.setModel(CalculusBisection.getTableData()); break; } } break; case "e^x-3x": if (null != methodComboBox.getSelectedItem().toString()) { switch (methodComboBox.getSelectedItem().toString()) { case "Newton-Raphson": CalculusNewtonRaphson.newtonRaphson3(Double.parseDouble(sp1TextField.getText()), decpoint); refreshTable(CalculusNewtonRaphson.createChartNewtonRapson(datasetFunction)); textArea.append(CalculusNewtonRaphson .textDataNewtonRapson(Integer.parseInt(decTextField.getText()))); table.setModel(CalculusNewtonRaphson.getTableData()); break; case "Secant": CalculusSecant.secant3(Double.parseDouble(sp1TextField.getText()), Double.parseDouble(sp2TextField.getText()), decpoint); refreshTable(CalculusSecant.createChartSecant(datasetFunction)); textArea.append( CalculusSecant.textDataSecant(Integer.parseInt(decTextField.getText()))); table.setModel(CalculusSecant.getTableData()); break; case "Bisection": CalculusBisection.bisection3(Double.parseDouble(sp1TextField.getText()), Double.parseDouble(sp2TextField.getText()), decpoint); refreshTable(CalculusBisection.createChartBisection(datasetFunction)); textArea.append( CalculusBisection.textDataBisection(Integer.parseInt(decTextField.getText()))); table.setModel(CalculusBisection.getTableData()); break; } } break; } } catch (Exception x) { JOptionPane.showMessageDialog(null, "Please insert a numerical value!"); } } }
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. ja v a 2 s .c o 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:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.explore.EnclosingBallController.java
private JFreeChart makeFDChart(TrackDataHolder trackDataHolder, FractalDimension fractalDimension) { XYSeries series = JFreeChartUtils.generateXYSeries(fractalDimension.getxValues(), fractalDimension.getyValues()); String seriesKey = "track " + trackDataHolder.getTrack().getTrackNumber() + ", well " + trackDataHolder.getTrack().getWellHasImagingType().getWell(); series.setKey(seriesKey);/*w w w. j ava2s. c o m*/ XYSeriesCollection collection = new XYSeriesCollection(series); double regression[] = Regression.getOLSRegression(collection, 0); // first the intercept, then the slope LineFunction2D linefunction2d = new LineFunction2D(regression[0], regression[1]); fractalDimension.setFD(regression[1]); JFreeChart chart = ChartFactory.createScatterPlot( seriesKey + " - FD = " + AnalysisUtils.roundThreeDecimals(fractalDimension.getFD()), "log(1/r)", "log(N)", collection, PlotOrientation.VERTICAL, false, true, false); // start, end, number of samples XYDataset dataset = DatasetUtilities.sampleFunction2D(linefunction2d, series.getMinX(), series.getMaxX(), 1000, "Fitted Regression Line"); chart.getXYPlot().setDataset(1, dataset); JFreeChartUtils.setupXYPlot(chart.getXYPlot()); JFreeChartUtils.setupSingleTrackPlot(chart, exploreTrackController.getExploreTrackPanel().getTracksList().getSelectedIndex(), true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 8, 8)); XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesPaint(0, GuiUtils.getDefaultColor()); chart.getXYPlot().setRenderer(1, renderer2); return chart; }
From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java
private XYDataset createXYNDDataset() { String[][] x = new String[xyLength][no_series]; double[][] y = new double[xyLength][no_series]; for (int index = 0; index < no_series; index++) for (int i = 0; i < xyLength; i++) x[i][index] = indepValues[i][index]; for (int index = 0; index < no_series; index++) for (int i = 0; i < xyLength; i++) y[i][index] = Double.parseDouble(depValues[i][index]); double mean = Double.parseDouble(x[0][0]); double stdDev = y[0][0]; Function2D normal = new NormalDistributionFunction2D(mean, stdDev); XYDataset dataset = DatasetUtilities.sampleFunction2D(normal, -10.0, 10.0, 100, "Normal"); return dataset; }