List of usage examples for org.jfree.data.statistics DefaultBoxAndWhiskerCategoryDataset DefaultBoxAndWhiskerCategoryDataset
public DefaultBoxAndWhiskerCategoryDataset()
From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesboxplot.ResultsProccessor.java
public void writeToFile(String outName) throws FileNotFoundException, UnsupportedEncodingException, IOException { //calcMeans(); // Create JFreeChart Dataset DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); HashMap<String, ArrayList<Double>> measuresFirst = algorithmMeasures.entrySet().iterator().next() .getValue();/*from w w w .ja v a 2s . c om*/ for (Map.Entry<String, ArrayList<Double>> measure : measuresFirst.entrySet()) { String measureName = measure.getKey(); //Double measureValue = measure.getValue(); dataset.clear(); for (Map.Entry<String, HashMap<String, ArrayList<Double>>> entry : algorithmMeasures.entrySet()) { String alg = entry.getKey(); ArrayList<Double> measureValues = entry.getValue().get(measureName); // Parse algorithm name to show it correctly String aName = alg.substring(0, alg.length() - 1); int startAlgName = aName.lastIndexOf("/"); aName = aName.substring(startAlgName + 1); dataset.add(measureValues, aName, measureName); } // Tutorial: http://www.java2s.com/Code/Java/Chart/JFreeChartBoxAndWhiskerDemo.htm final CategoryAxis xAxis = new CategoryAxis("Algorithm"); final NumberAxis yAxis = new NumberAxis("Value"); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); // Black and White int numItems = algorithmMeasures.size(); for (int i = 0; i < numItems; i++) { Color color = Color.DARK_GRAY; if (i % 2 == 1) { color = Color.LIGHT_GRAY; } renderer.setSeriesPaint(i, color); renderer.setSeriesOutlinePaint(i, Color.BLACK); } renderer.setMeanVisible(false); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("SansSerif", Font.BOLD, 10); //ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jchart = new JFreeChart("Assotiation Rules Measures - BoxPlot", font, plot, true); //StandardChartTheme.createLegacyTheme().apply(jchart); int width = 640 * 2; /* Width of the image */ int height = 480 * 2; /* Height of the image */ // JPEG File chart = new File(outName + "_" + measureName + "_boxplot.jpg"); ChartUtilities.saveChartAsJPEG(chart, jchart, width, height); // SVG SVGGraphics2D g2 = new SVGGraphics2D(width, height); Rectangle r = new Rectangle(0, 0, width, height); jchart.draw(g2, r); File BarChartSVG = new File(outName + "_" + measureName + "_boxplot.svg"); SVGUtils.writeToSVG(BarChartSVG, g2.getSVGElement()); } }
From source file:GeMSE.Visualization.BoxAndWhiskerPlot.java
private BoxAndWhiskerCategoryDataset CreateDataset() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); double[][] input = _space.GetContent(true); if (RowsCategoryRB.isSelected()) { for (int r = 0; r < _space.rowsID.length; r++) { ArrayList<Double> list = new ArrayList(); for (int c = 0; c < _space.colsID.length; c++) list.add(input[r][c]);/*from w w w . jav a2 s .c om*/ dataset.add(list, "Series ", _space.rowTitle[r]); } } else { for (int c = 0; c < _space.colsID.length; c++) { ArrayList<Double> list = new ArrayList(); for (int r = 0; r < _space.rowsID.length; r++) list.add(input[r][c]); dataset.add(list, "Series ", _space.colTitle[c]); } } return dataset; }
From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java
/** * Create a box plot qimage.//from w w w. j a v a2s .c o m * @param data Data to use * @return a QImage */ public QImage createBoxPlot(final double[] data, final String unit) { if (data == null || data.length < 2) return null; this.width = this.width / 2; List<Float> listData = new ArrayList<Float>(data.length); for (int i = 0; i < data.length; i++) listData.add((float) data[i]); DefaultBoxAndWhiskerCategoryDataset defaultboxandwhiskercategorydataset = new DefaultBoxAndWhiskerCategoryDataset(); defaultboxandwhiskercategorydataset.add(listData, "Distances", "Min"); JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Intensities Boxplot", "", "Distance" + unitLegend(unit), defaultboxandwhiskercategorydataset, false); addTransparency(chart); final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB, null); return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height, QImage.Format.Format_ARGB32); }
From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java
/** * Some checks for the remove method./*from w ww. ja va 2 s .c o m*/ */ @Test public void testRemove() { DefaultBoxAndWhiskerCategoryDataset data = new DefaultBoxAndWhiskerCategoryDataset(); boolean pass = false; try { data.remove("R1", "R2"); } catch (UnknownKeyException e) { pass = true; } assertTrue(pass); data.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()), "R1", "C1"); assertEquals(new Range(7.0, 8.0), data.getRangeBounds(false)); assertEquals(new Range(7.0, 8.0), data.getRangeBounds(true)); data.add(new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, new ArrayList()), "R2", "C1"); assertEquals(new Range(7.0, 9.5), data.getRangeBounds(false)); assertEquals(new Range(7.0, 9.5), data.getRangeBounds(true)); data.remove("R1", "C1"); assertEquals(new Range(8.5, 9.5), data.getRangeBounds(false)); assertEquals(new Range(8.5, 9.5), data.getRangeBounds(true)); }
From source file:weka.core.ChartUtils.java
/** * Create a box plot from summary data (mean, median, q1, q3, min, max, * minOutlier, maxOutlier, list of outliers) * /*from ww w .j a v a 2s . c o m*/ * @param summary summary data * @param outliers list of outlier values * @param additionalArgs additional options to the renderer * @return a box plot chart * @throws Exception if a problem occurs */ protected static JFreeChart getBoxPlotFromSummaryData(List<Double> summary, List<Double> outliers, List<String> additionalArgs) throws Exception { if (summary.size() != 8) { throw new Exception("Expected 8 values in the summary argument: mean, median, " + "q1, q3, min, max, minOutlier, maxOutlier"); } String plotTitle = "Box Plog"; String userTitle = getOption(additionalArgs, "-title"); plotTitle = (userTitle != null) ? userTitle : plotTitle; String xLabel = getOption(additionalArgs, "-x-label"); xLabel = xLabel == null ? "" : xLabel; String yLabel = getOption(additionalArgs, "-y-label"); yLabel = yLabel == null ? "" : yLabel; DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); Double mean = summary.get(0); Double median = summary.get(1); Double q1 = summary.get(2); Double q3 = summary.get(3); Double min = summary.get(4); Double max = summary.get(5); Double minOutlier = summary.get(6); Double maxOutlier = summary.get(7); if (mean.isNaN() || median.isNaN() || min.isNaN() || max.isNaN() || q1.isNaN() || q3.isNaN()) { throw new Exception("NaN in summary data - can't generate box plot"); } BoxAndWhiskerItem item = new BoxAndWhiskerItem(mean, median, q1, q3, min, max, minOutlier, maxOutlier, outliers); dataset.add(item, "", ""); CategoryAxis xAxis = new CategoryAxis(); NumberAxis yAxis = new NumberAxis(); yAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setMaximumBarWidth(0.15); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(plotTitle, new Font("SansSerif", Font.BOLD, 12), plot, false); return chart; }
From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java
/** * Create a boxplot.//www . j a v a2 s .c om * @param results Results to use * @return a QImage */ public QImage createBoxPlot(final CorsenResult results, final String unit) { this.width = this.width / 2; Map<Particle3D, Distance> distsMin = results.getMinDistances(); Map<Particle3D, Distance> distsMax = results.getMaxDistances(); if (distsMin == null || distsMax == null) return null; List<Float> listMin = new ArrayList<Float>(); List<Float> listMax = new ArrayList<Float>(); for (Map.Entry<Particle3D, Distance> e : distsMin.entrySet()) { final Particle3D p = e.getKey(); final long intensity = p.getIntensity(); final float distanceMin = e.getValue().getDistance(); final float distanceMax = distsMax.get(p).getDistance(); for (int i = 0; i < intensity; i++) { listMin.add(distanceMin); listMax.add(distanceMax); } } DefaultBoxAndWhiskerCategoryDataset defaultboxandwhiskercategorydataset = new DefaultBoxAndWhiskerCategoryDataset(); if (results.getMinAnalyser().count() > 0) defaultboxandwhiskercategorydataset .add(convertDistanceAnalyserToBoxAndWhiskerItem(results.getMinAnalyser()), "Distances", "Min"); // defaultboxandwhiskercategorydataset.add(listMin, "Distances", "Min"); // defaultboxandwhiskercategorydataset.add(listMax, "Distances", "Max"); JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Intensities Boxplot", "", "Distance" + unitLegend(unit), defaultboxandwhiskercategorydataset, false); addTransparency(chart); // CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); // // chart.setBackgroundPaint(Color.white); // categoryplot.setBackgroundPaint(Color.lightGray); // categoryplot.setDomainGridlinePaint(Color.white); // categoryplot.setDomainGridlinesVisible(true); // categoryplot.setRangeGridlinePaint(Color.white); // // NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); // numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB, null); return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height, QImage.Format.Format_ARGB32); }
From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java
private static BoxAndWhiskerCategoryDataset createBoxAndWhiskerCategoryDataset() { int SERIES_COUNT = 3; int CATEGORY_COUNT = 2; int VALUE_COUNT = 10; DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); for (int s = 0; s < SERIES_COUNT; s++) { for (int c = 0; c < CATEGORY_COUNT; c++) { List<Double> values = createValueList(0, 20.0, VALUE_COUNT); dataset.add(values, "Series " + s, "Category " + c); }//w ww. j av a 2 s . c om } return dataset; }
From source file:edu.msu.cme.rdp.classifier.train.validation.distance.TaxaSimilarityMain.java
public void createPlot(String plotTitle, File outdir) throws IOException { XYSeriesCollection dataset = new XYSeriesCollection(); DefaultBoxAndWhiskerCategoryDataset scatterDataset = new DefaultBoxAndWhiskerCategoryDataset(); PrintStream boxchart_dataStream = new PrintStream(new File(outdir, plotTitle + ".boxchart.txt")); boxchart_dataStream.println(/*from www .java2 s . co m*/ "#\tkmer" + "\trank" + "\t" + "max" + "\t" + "avg" + "\t" + "min" + "\t" + "Q1" + "\t" + "median" + "\t" + "Q3" + "\t" + "98Pct" + "\t" + "2Pct" + "\t" + "comparisons" + "\t" + "sum"); for (int i = 0; i < ranks.size(); i++) { long[] countArray = sabCoutMap.get(ranks.get(i)); if (countArray == null) continue; double sum = 0.0; int max = 0; int min = 100; double mean = 0; int Q1 = -1; int median = -1; int Q3 = -1; int pct_98 = -1; int pct_2 = -1; long comparisons = 0; int minOutlier = 0; // we don't care about the outliers int maxOutlier = 0; // XYSeries series = new XYSeries(ranks.get(i)); for (int c = 0; c < countArray.length; c++) { if (countArray[c] == 0) continue; comparisons += countArray[c]; sum += countArray[c] * c; if (c < min) { min = c; } if (c > max) { max = c; } } // create series double cum = 0; for (int c = 0; c < countArray.length; c++) { if (countArray[c] == 0) continue; cum += countArray[c]; int pct = (int) Math.floor(100 * cum / comparisons); series.add(c, pct); if (pct_2 == -1 && pct >= 5) { pct_2 = c; } if (Q3 == -1 && pct >= 25) { Q3 = c; } if (median == -1 && pct >= 50) { median = c; } if (Q1 == -1 && pct >= 75) { Q1 = c; } if (pct_98 == -1 && pct >= 98) { pct_98 = c; } } if (!series.isEmpty()) { dataset.addSeries(series); BoxAndWhiskerItem item = new BoxAndWhiskerItem(sum / comparisons, median, Q1, Q3, pct_2, pct_98, minOutlier, maxOutlier, new ArrayList()); scatterDataset.add(item, ranks.get(i), ""); boxchart_dataStream.println("#\t" + GoodWordIterator.getWordsize() + "\t" + ranks.get(i) + "\t" + max + "\t" + format.format(sum / comparisons) + "\t" + min + "\t" + Q1 + "\t" + median + "\t" + Q3 + "\t" + pct_98 + "\t" + pct_2 + "\t" + comparisons + "\t" + sum); } } boxchart_dataStream.close(); Font lableFont = new Font("Helvetica", Font.BOLD, 28); JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, "Similarity%", "Percent Comparisions", dataset, PlotOrientation.VERTICAL, true, true, false); ((XYPlot) chart.getPlot()).getRenderer().setStroke(new BasicStroke(2.0f)); chart.getLegend().setItemFont(new Font("Helvetica", Font.BOLD, 24)); chart.getTitle().setFont(lableFont); ((XYPlot) chart.getPlot()).getDomainAxis().setLabelFont(lableFont); ((XYPlot) chart.getPlot()).getDomainAxis().setTickLabelFont(lableFont); ValueAxis rangeAxis = ((XYPlot) chart.getPlot()).getRangeAxis(); rangeAxis.setRange(0, 100); rangeAxis.setTickLabelFont(lableFont); rangeAxis.setLabelFont(lableFont); ((NumberAxis) rangeAxis).setTickUnit(new NumberTickUnit(5)); ChartUtilities.writeScaledChartAsPNG(new PrintStream(new File(outdir, plotTitle + ".linechart.png")), chart, 800, 1000, 3, 3); BoxPlotUtils.createBoxplot(scatterDataset, new PrintStream(new File(outdir, plotTitle + ".boxchart.png")), plotTitle, "Rank", "Similarity%", lableFont); }
From source file:edu.ucla.stat.SOCR.analyses.gui.Chart.java
private BoxAndWhiskerCategoryDataset createBoxAndWhiskerDataset(int seriesCount, int categoryCount, String[] seriesName, String[][] categoryName, double[][][] values) { List<Double> list; DefaultBoxAndWhiskerCategoryDataset result = new DefaultBoxAndWhiskerCategoryDataset(); for (int s = 0; s < seriesCount; s++) { for (int c = 0; c < categoryCount; c++) { list = new java.util.ArrayList<Double>(); for (int i = 0; i < Array.getLength(values[s][c]); i++) list.add(new Double(values[s][c][i])); result.add(list, seriesName[s], categoryName[s][c]); }//w ww.j a v a 2 s . com } return result; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellAnalysisController.java
/** * Generate the dataset for the box plot with the track speeds. * * @return a DefaultBoxAndWhiskerCategoryDataset *//*from w ww .j av a 2 s .com*/ private DefaultBoxAndWhiskerCategoryDataset getSpeedBoxPlotDataset() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); singleCellMainController.getFilteringMap().keySet().stream().forEach((singleCellConditionDataHolder) -> { dataset.add(Arrays.asList(singleCellConditionDataHolder.getTrackSpeedsVector()), singleCellConditionDataHolder.getPlateCondition().toString(), ""); }); return dataset; }