List of usage examples for org.jfree.chart ChartFactory createHistogram
public static JFreeChart createHistogram(String title, String xAxisLabel, String yAxisLabel, IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:Core.CircuitEvolution.QPace4.HistogramDemo.java
/** * Creates a chart.//from www . j a v a 2 s .com * * @param dataset * a dataset. * * @return The chart. */ private JFreeChart createChart(IntervalXYDataset dataset) { JFreeChart chart = ChartFactory.createHistogram("Histogram Demo", null, null, dataset, PlotOrientation.VERTICAL, true, false, false); chart.getXYPlot().setForegroundAlpha(0.75f); return chart; }
From source file:com.compomics.pepshell.view.statistics.RatioStatisticsScatterplotPane.java
@Override public void setGraphData(PepshellProtein aPepshellProtein) { List<XYLineAnnotation> annotations = new ArrayList<>(); XYSeriesCollection allExperiments = new XYSeriesCollection(); for (Experiment anExperiment : experiments) { int proteinIndex = anExperiment.getProteins().indexOf(aPepshellProtein); if (proteinIndex != -1) { XYSeries anExperimentSeries = new XYSeries(anExperiment.getExperimentName()); PepshellProtein experimentPepshellProtein = anExperiment.getProteins().get(proteinIndex); for (PeptideGroup aGroup : experimentPepshellProtein.getPeptideGroups()) { PeptideInterface shortestPeptide = aGroup.getRepresentativePeptide(); if (shortestPeptide instanceof QuantedPeptide && ((QuantedPeptide) shortestPeptide).getRatio() != null) { Double value = Math.log(((QuantedPeptide) shortestPeptide).getRatio()) / Math.log(2); //Double value = ((QuantedPeptide) shortestPeptide).getRatio(); if (value == Double.NEGATIVE_INFINITY) { value = 0.0;/* w w w . j a v a2 s . co m*/ } double barWithErrors = (shortestPeptide.getEndProteinMatch() + shortestPeptide.getBeginningProteinMatch()) / 2; double error = Math.log(((QuantedPeptide) shortestPeptide).getStandardError()) / Math.log(2); //double error =((QuantedPeptide) shortestPeptide).getStandardError(); XYLineAnnotation vertical = new XYLineAnnotation(barWithErrors, value - error, barWithErrors, value + error, new BasicStroke(), Color.black); XYLineAnnotation horizontalUpper = new XYLineAnnotation(value + error - 0.25, value + error, value + error + 0.25, value + error, new BasicStroke(), Color.black); XYLineAnnotation horizontalLower = new XYLineAnnotation(value - error - 0.25, value - error, value - error + 0.25, value - error, new BasicStroke(), Color.black); annotations.add(vertical); annotations.add(horizontalUpper); annotations.add(horizontalLower); for (int i = shortestPeptide.getBeginningProteinMatch(); i < shortestPeptide .getEndProteinMatch(); i++) { anExperimentSeries.add(i, value); } } } allExperiments.addSeries(anExperimentSeries); } } JFreeChart ratioChart = ChartFactory.createHistogram( "ratio for " + aPepshellProtein.getVisibleAccession() + " over all experiments", "peptide start", "log^2 ratio", allExperiments, PlotOrientation.VERTICAL, true, true, false); chart.setChart(ratioChart); for (XYLineAnnotation anAnnotation : annotations) { ((XYPlot) ratioChart.getPlot()).addAnnotation(anAnnotation); } prettifyChart(ratioChart); }
From source file:Trabalho.HistogramaHSB.java
public ChartPanel criaHistograma() throws IOException { //pega a imagem BufferedImage img = pegaImagem(); //w pega a largura da imagem - h pega a altura da imagem int w = img.getWidth(); int h = img.getHeight(); //d calcula o tamanho da imagem int d = (w * h); //red, green e blue iro receber os tons de cor antigo da imagem - u vai receber o RGB da cor int red, green, blue, u; //retorna rgb no mtodo float[] hsb;// ww w. j a v a2 s . co m int[] vetH = new int[256]; int[] vetS = new int[256]; int[] vetB = new int[256]; float hue, sat, bri; //cAux e oldColor pegam os tons originais da imagem - newColor pega os tons aps o clculo Color oldColor; Color newColor; //for responsvel por substituir os tons antigos pelos novos; percorrem a imagem por largura e altura for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { u = img.getRGB(i, j); //u vai receber o RGB da posio i, j oldColor = new Color(u); //oldColor instanciado e recebe o valor de u //cada cor recebe o valor do tom original red = oldColor.getRed(); green = oldColor.getGreen(); blue = oldColor.getBlue(); hsb = Color.RGBtoHSB(red, green, blue, null); hue = hsb[0]; sat = hsb[1]; bri = hsb[2]; // System.out.println("RGB [" + red + "," + green + "," + blue + "] converted to HSB [" + hue + "," + sat + "," + bri + "]"); // hue = hue * 360; // int convH = Integer.valueOf(new Float(hue).intValue()); // vetH[convH]++; // // sat = sat * 100; // int convS = Integer.valueOf(new Float(sat).intValue()); // vetS[convS]++; // // bri = bri * 100; // int convB = Integer.valueOf(new Float(bri).intValue()); // vetB[convB]++; newColor = new Color(hue, sat, bri); //seta o RGB da imagem nas posies i, j pegando os valores da newColor img.setRGB(i, j, newColor.getRGB()); } } File ouptut = new File("D:\\ProjetosNetBeans\\PDI\\src\\imagens\\5.jpeg"); ImageIO.write(img, "png", ouptut); dataset = new HistogramDataset(); //pega o RGB r = raster.getSamples(0, 0, w, h, 0, r); dataset.addSeries("Red", r, 360); r = raster.getSamples(0, 0, w, h, 1, r); dataset.addSeries("Green", r, 101); r = raster.getSamples(0, 0, w, h, 2, r); dataset.addSeries("Blue", r, 101); JFreeChart chart = ChartFactory.createHistogram("Histograma", "Pixels", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); //Plota as cores XYPlot plot = (XYPlot) chart.getPlot(); renderer = (XYBarRenderer) plot.getRenderer(); renderer.setBarPainter(new StandardXYBarPainter()); //vermelho, verde, azul Paint[] paintArray = { new Color(0x80ff0000, true), new Color(0x8000ff00, true), new Color(0x800000ff, true) }; //desenhando o grfico plot.setDrawingSupplier( new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); ChartPanel panel = new ChartPanel(chart); panel.setMouseWheelEnabled(true); return panel; }
From source file:org.utgenome.core.cui.DrawHistogram.java
public void execute() throws Exception { InputStream in = null;//from w w w .ja v a2 s .c om 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:playground.thibautd.parknride.analysis.ParkAndRideTripsAnalyzer.java
private static ChartUtil createProportionHistogram(final String title, final String xName, final String yName, final double[] values, final int nBins, final double min, final double max) { HistogramDataset dataset = new HistogramDataset(); dataset.addSeries(xName, values, nBins, min, max); JFreeChart chart = ChartFactory.createHistogram(title, xName, yName, dataset, PlotOrientation.VERTICAL, false, false, false);//w ww. j a v a2s . c o m tuneHistogramAppearence(chart); return new WrapperChartUtil(chart); }
From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java
/** * Creates a histogram chart that displays the given integer histogram data. * //from w w w .ja v a 2 s. c o m * @param aHistogram * Complex parameter that stores the data to be visualized. * @param aSettings * Settings group for integer histogram. * @return Newly created chart control. */ public static JFreeChart createHistogram(IntHistogram aHistogram, IntHistogramGroup aSettings) { XYSeriesCollection collection = fromIntHistogram(aHistogram); JFreeChart chart = ChartFactory.createHistogram(null, // title convertLabel(aSettings.axes.getDomainAxisLabel()), // label of X axis convertLabel(aSettings.axes.getRangeAxisLabel()), // label of Y axis collection, // dataset PlotOrientation.VERTICAL, // orientation false, // create legend false, // display tooltips false); // generate urls XYPlot plot = chart.getXYPlot(); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); updateGeneral(plot, aSettings.general); updateAxes(chart, aSettings.axes, aSettings.grid); updateBars(plot, aSettings.bars); chart.setBackgroundPaint(null); return chart; }
From source file:chart.statistic.HistogramChart.java
public JFreeChart createChart() { JFreeChart chart = ChartFactory.createHistogram(mr.getLabel(), null, null, dataset, PlotOrientation.VERTICAL, false, // legende false, false);//from ww w .j a v a 2 s . c om chart.getXYPlot().setForegroundAlpha(0.75f); return chart; }
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); }/*from ww w .ja v a2 s .co 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:com.rapidminer.gui.viewer.metadata.model.NumericalAttributeStatisticsModel.java
/** * Creates the histogram chart./*from w w w. jav a2 s .c o m*/ * * @param exampleSet * @return */ private JFreeChart createHistogramChart(ExampleSet exampleSet) { JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(exampleSet), PlotOrientation.VERTICAL, false, false, false); AbstractAttributeStatisticsModel.setDefaultChartFonts(chart); chart.setBackgroundPaint(null); chart.setBackgroundImageAlpha(0.0f); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); plot.setOutlineVisible(false); plot.setRangeZeroBaselineVisible(false); plot.setDomainZeroBaselineVisible(false); plot.setBackgroundPaint(COLOR_INVISIBLE); plot.setBackgroundImageAlpha(0.0f); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NUMERICAL)); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); return chart; }
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 www. j a v a 2s. 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; }