List of usage examples for org.jfree.data.statistics HistogramDataset setType
public void setType(HistogramType type)
From source file:net.imglib2.script.analysis.Histogram.java
/** Return the JFreeChart with this histogram, and as a side effect, show it in a JFrame * that provides the means to edit the dimensions and also the plot properties via a popup menu. */ public JFreeChart asChart(final boolean show) { double[] d = new double[this.size()]; int i = 0;/*from w ww. ja v a2s . c o m*/ for (Number num : this.values()) d[i++] = num.doubleValue(); HistogramDataset hd = new HistogramDataset(); hd.setType(HistogramType.RELATIVE_FREQUENCY); String title = "Histogram"; hd.addSeries(title, d, d.length); JFreeChart chart = ChartFactory.createHistogram(title, "", "", hd, PlotOrientation.VERTICAL, false, false, false); setTheme(chart); if (show) { JFrame frame = new JFrame(title); frame.getContentPane().add(new ChartPanel(chart)); frame.pack(); frame.setVisible(true); } return chart; }
From source file:sim.util.media.chart.HistogramGenerator.java
/** Adds a series, plus a (possibly null) SeriesChangeListener which will receive a <i>single</i> event if/when the series is deleted from the chart by the user. Returns the series attributes. */ public SeriesAttributes addSeries(double[] vals, int bins, String name, SeriesChangeListener stopper) { if (vals == null || vals.length == 0) vals = new double[] { 0 }; // ya gotta have at least one val HistogramDataset dataset = (HistogramDataset) (getSeriesDataset()); int i = dataset.getSeriesCount(); dataset.setType(histogramType); // It looks like the histograms reset dataset.addSeries(new UniqueString(name), vals, bins); // need to have added the dataset BEFORE calling this since it'll try to change the name of the series HistogramSeriesAttributes csa = new HistogramSeriesAttributes(this, name, i, vals, bins, stopper); seriesAttributes.add(csa);//from w ww . j a va 2s. c o m revalidate(); // display the new series panel update(); // won't update properly unless I force it here by letting all the existing scheduled events to go through. Dumb design. :-( SwingUtilities.invokeLater(new Runnable() { public void run() { update(); } }); return csa; }
From source file:org.utgenome.core.cui.DrawHistogram.java
public void execute() throws Exception { InputStream in = null;/*w ww . j ava 2 s. co m*/ if ("-".equals(input)) { _logger.info("reading from STDIN"); in = new StandardInputStream(); } else { _logger.info("reading from " + input); in = new FileInputStream(input); } List<Double> data = new ArrayList<Double>(); BufferedReader dataSetInput = new BufferedReader(new InputStreamReader(in)); int lineCount = 1; try { // read data set boolean cutOffTail = !Double.isNaN(xMax); boolean cutOffHead = !Double.isNaN(xMin); for (String line; (line = dataSetInput.readLine()) != null; lineCount++) { if (lineCount % 100000 == 0) _logger.info(String.format("read %,d data points", lineCount)); if (line.startsWith("#")) continue; double v = Double.parseDouble(line); if (cutOffTail && v > xMax) continue; if (cutOffHead && v < xMin) continue; data.add(v); } double[] value = new double[data.size()]; for (int i = 0; i < data.size(); ++i) { value[i] = data.get(i); } // draw histogram HistogramDataset dataSet = new HistogramDataset(); dataSet.setType(HistogramType.FREQUENCY); dataSet.addSeries("data", value, numBins); JFreeChart chart = ChartFactory.createHistogram(null, null, "Frequency", dataSet, PlotOrientation.VERTICAL, false, false, false); if (title != null) { chart.setTitle(title); } ValueAxis domainAxis = chart.getXYPlot().getDomainAxis(); if (cutOffHead) { domainAxis.setLowerBound(xMin); } if (cutOffTail) { domainAxis.setUpperBound(xMax); } if (xLabel != null) { domainAxis.setLabel(xLabel); } if (yLog) { LogarithmicAxis logAxis = new LogarithmicAxis("Frequency"); logAxis.setAllowNegativesFlag(true); logAxis.setAutoRangeIncludesZero(true); chart.getXYPlot().setRangeAxis(logAxis); } if (!Double.isNaN(yMin)) { chart.getXYPlot().getRangeAxis().setLowerBound(yMin); } if (!Double.isNaN(yMax)) { chart.getXYPlot().getRangeAxis().setUpperBound(yMax); } File outputFile = new File(output); _logger.info("output to " + outputFile); ChartUtilities.saveChartAsPNG(outputFile, chart, width, height); } catch (Exception e) { throw new Exception(String.format("error at line %d: %s", lineCount, e)); } }
From source file:edu.gmu.cs.sim.util.media.chart.HistogramGenerator.java
/** Adds a series, plus a (possibly null) SeriesChangeListener which will receive a <i>single</i> event if/when the series is deleted from the chart by the user. Returns the series attributes. */ public SeriesAttributes addSeries(double[] vals, int bins, String name, SeriesChangeListener stopper) { if (vals == null || vals.length == 0) { vals = new double[] { 0 }; // ya gotta have at least one val }/*from w ww. j a v a 2 s . c om*/ HistogramDataset dataset = (HistogramDataset) (getSeriesDataset()); int i = dataset.getSeriesCount(); dataset.setType(histogramType); // It looks like the histograms reset dataset.addSeries(new UniqueString(name), vals, bins); // need to have added the dataset BEFORE calling this since it'll try to change the name of the series HistogramSeriesAttributes csa = new HistogramSeriesAttributes(this, name, i, vals, bins, stopper); seriesAttributes.add(csa); revalidate(); // display the new series panel update(); // won't update properly unless I force it here by letting all the existing scheduled events to go through. Dumb design. :-( SwingUtilities.invokeLater(new Runnable() { public void run() { update(); } }); return csa; }
From source file:playground.anhorni.surprice.analysis.ModeSharesEventHandler.java
public HistogramDataset getHistogramDataset(final int nBins) { HistogramDataset output = new HistogramDataset(); output.setType(HistogramType.RELATIVE_FREQUENCY); ArrayList<Double> croppedData = new ArrayList<Double>(); for (String mode : this.rawData.keySet()) { for (double d : this.rawData.get(mode).getElements()) { if (d < this.maxXYForPlotting) { croppedData.add(d);/*ww w.jav a 2s .c o m*/ } } output.addSeries(mode, Utils.convert(croppedData), nBins); } return output; }
From source file:herbie.running.analysis.ModeSharesEventHandler.java
public HistogramDataset getHistogramDataset(final int nBins) { HistogramDataset output = new HistogramDataset(); output.setType(HistogramType.RELATIVE_FREQUENCY); for (String mode : this.rawData.keySet()) { output.addSeries(mode, this.rawData.get(mode).getElements(), nBins); }// ww w . j a v a2s . c om return output; }
From source file:MSUmpire.DIA.MixtureModelKDESemiParametric.java
public void GeneratePlot(String pngfile) throws IOException { String modelfile = FilenameUtils.getFullPath(pngfile) + "/" + FilenameUtils.getBaseName(pngfile) + "_ModelPoints.txt"; FileWriter writer = new FileWriter(modelfile); double[] IDObs = new double[IDEmpiricalDist.getN()]; double[] DecoyObs = new double[DecoyEmpiricalDist.getN()]; for (int i = 0; i < IDEmpiricalDist.getN(); i++) { IDObs[i] = IDEmpiricalDist.getObs(i); }/*w w w . ja va 2 s .c o m*/ for (int i = 0; i < DecoyEmpiricalDist.getN(); i++) { DecoyObs[i] = DecoyEmpiricalDist.getObs(i); } XYSeries model1 = new XYSeries("Incorrect matches"); XYSeries model2 = new XYSeries("Correct matches"); XYSeries model3 = new XYSeries("All target hits"); writer.write("UScore\tModel\tCorrect\tDecoy\n"); for (int i = 0; i < NoBinPoints; i++) { model1.add(model_kde_x[i], decoy_kde_y[i]); model2.add(model_kde_x[i], correct_kde_y[i]); model3.add(model_kde_x[i], model_kde_y[i]); writer.write(model_kde_x[i] + "\t" + model_kde_y[i] + "\t" + correct_kde_y[i] + "\t" + decoy_kde_y[i] + "\n"); } writer.close(); MixtureModelProb = new float[NoBinPoints + 1][3]; float positiveaccu = 0f; float negativeaccu = 0f; MixtureModelProb[0][0] = (float) model2.getMaxX() + Float.MIN_VALUE; MixtureModelProb[0][1] = 1f; MixtureModelProb[0][2] = 1f; for (int i = 1; i < NoBinPoints + 1; i++) { double positiveNumber = correct_kde_y[NoBinPoints - i]; double negativeNumber = decoy_kde_y[NoBinPoints - i]; MixtureModelProb[i][0] = (float) model_kde_x[NoBinPoints - i]; positiveaccu += positiveNumber; negativeaccu += negativeNumber; MixtureModelProb[i][2] = 0.999999f * (float) (positiveNumber / (negativeNumber + positiveNumber)); MixtureModelProb[i][1] = 0.999999f * (float) (positiveaccu / (negativeaccu + positiveaccu)); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(model1); dataset.addSeries(model2); dataset.addSeries(model3); HistogramDataset histogramDataset = new HistogramDataset(); histogramDataset.setType(HistogramType.SCALE_AREA_TO_1); histogramDataset.addSeries("ID hits", IDObs, 100); histogramDataset.addSeries("Decoy hits", DecoyObs, 100); //histogramDataset.addSeries("Model hits", ModelObs, 100); JFreeChart chart = ChartFactory.createHistogram(FilenameUtils.getBaseName(pngfile), "Score", "Hits", histogramDataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = chart.getXYPlot(); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setRange(min, max); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setForegroundAlpha(0.8f); chart.setBackgroundPaint(Color.white); XYLineAndShapeRenderer render = new XYLineAndShapeRenderer(); plot.setDataset(1, dataset); plot.setRenderer(1, render); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); try { ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600); } catch (IOException e) { } }
From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java
private void updateChart(SimpleFeatureCollection features, String field) { int bin = spinner.getSelection(); double[] values = getValues(features, field); HistogramDataset dataset = new HistogramDataset(); dataset.addSeries(field, values, bin, minMaxVisitor.getMinX(), minMaxVisitor.getMaxX()); dataset.setType(histogramType); JFreeChart chart = ChartFactory.createHistogram(EMPTY, null, null, dataset, PlotOrientation.VERTICAL, false, false, false);//from w w w .j a va 2s . com // 1. Create a single plot containing both the scatter and line chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(0.85F); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY); plot.setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY); int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis valueAxis = new NumberAxis(cboField.getText()); valueAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); valueAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); valueAxis.setAutoRange(false); valueAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX()); String rangeAxisLabel = histogramType == HistogramType.FREQUENCY ? "Frequency" : "Ratio"; //$NON-NLS-1$ //$NON-NLS-2$ NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel); rangeAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); rangeAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); if (histogramType == HistogramType.FREQUENCY) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setShadowVisible(false); CustomXYBarPainter.selectedColumn = -1; // init renderer.setBarPainter(new CustomXYBarPainter()); renderer.setAutoPopulateSeriesFillPaint(true); renderer.setAutoPopulateSeriesPaint(true); renderer.setShadowXOffset(3); renderer.setMargin(0.01); renderer.setBaseItemLabelsVisible(true); ItemLabelPosition pos = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_CENTER); renderer.setBasePositiveItemLabelPosition(pos); XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator(); renderer.setBaseToolTipGenerator(plotToolTip); // color GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, java.awt.Color.GRAY, 0.0f, 0.0f, java.awt.Color.LIGHT_GRAY); renderer.setSeriesPaint(0, gp0); plot.setDomainAxis(0, valueAxis); plot.setRangeAxis(0, rangeAxis); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.RED); lineRenderer.setSeriesStroke(0, new BasicStroke(2f)); // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); xLineAxis.setAutoRange(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); yLineAxis.setAutoRange(false); double maxYValue = Double.MIN_VALUE; for (int i = 0; i < dataset.getItemCount(0); i++) { maxYValue = Math.max(maxYValue, dataset.getYValue(0, i)); } XYSeriesCollection lineDatset = new XYSeriesCollection(); // Vertical Average XYSeries vertical = new XYSeries("Average"); //$NON-NLS-1$ vertical.add(minMaxVisitor.getAverageX(), 0); vertical.add(minMaxVisitor.getAverageX(), maxYValue); lineDatset.addSeries(vertical); plot.setDataset(1, lineDatset); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); chartComposite.setChart(chart); chartComposite.forceRedraw(); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellAnalysisController.java
/** * For a single well, generate an histogram dataset. * * @param data/*from w ww. j a v a 2 s . c om*/ * @param seriesKey * @param mapTo360 * @return an HistogramDataset */ private HistogramDataset getHistogramDatasetForACondition( SingleCellConditionDataHolder singleCellConditionDataHolder, String seriesKey, int bins) { HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.RELATIVE_FREQUENCY); double[] toPrimitive = ArrayUtils.toPrimitive( AnalysisUtils.excludeNullValues(singleCellConditionDataHolder.getTurningAnglesVector())); double[] mappedData = new double[toPrimitive.length]; for (int i = 0; i < toPrimitive.length; i++) { if (toPrimitive[i] > 0) { mappedData[i] = toPrimitive[i]; } else { mappedData[i] = toPrimitive[i] + 360; } } double[] toAdd = mappedData; dataset.addSeries(seriesKey, toAdd, bins); return dataset; }
From source file:playground.christoph.evacuation.analysis.EvacuationTimePictureWriter.java
private JFreeChart createHistogramChart(String transportMode, double[] travelTimes) { HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.RELATIVE_FREQUENCY); dataset.addSeries("evacuation travel time " + transportMode, travelTimes, 20); JFreeChart chart = ChartFactory.createHistogram(null, null, "frequency", dataset, PlotOrientation.VERTICAL, true, false, false);//from www .j av a2s .c om chart.getXYPlot().setForegroundAlpha(0.75f); /* * set x-axis range */ double min = 0.0; double max = maxEvacuationTime; if (limitMaxEvacuationTime) { double cutOffValue = meanEvacuationTime + standardDeviation * evacuationTimeCutOffFactor; max = cutOffValue; } chart.getXYPlot().getDomainAxis().setLowerBound(min); chart.getXYPlot().getDomainAxis().setUpperBound(max); return chart; }