List of usage examples for org.jfree.chart.plot XYPlot addAnnotation
public void addAnnotation(XYAnnotation annotation)
From source file:asl.util.PlotMaker.java
public void plotZNE_3x3(ArrayList<double[]> channelData, double[] xsecs, int nstart, int nend, String eventString, String plotString) { // Expecting 9 channels packed like: Panel Trace1 Trace2 Trace3 // channels[0] = 00-LHZ 1 00-LHZ 10-LHZ 20-LHZ // channels[1] = 00-LHND 2 00-LHND 10-LHND 20-LHND // channels[2] = 00-LHED 3 00-LHED 10-LHED 20-LHED // channels[3] = 10-LHZ // channels[4] = 10-LHND // channels[5] = 10-LHED // channels[6] = 20-LHZ // channels[7] = 20-LHND // channels[8] = 20-LHED final String plotTitle = String.format("%04d%03d [Stn:%s] [Event:%s] %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, eventString, plotString); final String pngName = String.format("%s/%s.%s.%s.png", outputDir, eventString, station, plotString); File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotZNE_3x3: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return;/*from w w w . j a v a 2s .c o m*/ } if (channelData.size() != channels.length) { System.out.format("== plotZNE_3x3: Error: We have [%d channels] but [%d channelData]\n", channels.length, channelData.size()); return; } XYSeries[] series = new XYSeries[channels.length]; for (int i = 0; i < channels.length; i++) { series[i] = new XYSeries(channels[i].toString()); double[] data = channelData.get(i); //for (int k = 0; k < xsecs.length; k++){ for (int k = 0; k < data.length; k++) { series[i].add(xsecs[k], data[k]); } } // I. Panel I = Verticals // Use the first data array, within the plotted range (nstart - nend) to scale the plots: double[] data = channelData.get(0); double ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Paint[] paints = new Paint[] { Color.red, Color.blue, Color.green }; for (int i = 0; i < paints.length; i++) { renderer.setSeriesPaint(i, paints[i]); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); } final NumberAxis verticalAxis = new NumberAxis("Displacement (m)"); verticalAxis.setRange(new Range(-ymax, ymax)); //verticalAxis.setTickUnit( new NumberTickUnit(5) ); final NumberAxis horizontalAxis = new NumberAxis("Time (s)"); horizontalAxis.setRange(new Range(nstart, nend)); //horizontalAxis.setRange( new Range(0.00009 , 110) ); final NumberAxis hAxis = new NumberAxis("Time (s)"); hAxis.setRange(new Range(nstart, nend)); final XYSeriesCollection seriesCollection1 = new XYSeriesCollection(); seriesCollection1.addSeries(series[0]); seriesCollection1.addSeries(series[3]); seriesCollection1.addSeries(series[6]); //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, null, verticalAxis, renderer); //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, horizontalAxis, verticalAxis, renderer); final XYPlot xyplot1 = new XYPlot((XYDataset) seriesCollection1, hAxis, verticalAxis, renderer); double x = .95 * xsecs[nend]; double y = .90 * ymax; XYTextAnnotation annotation1 = new XYTextAnnotation("Vertical", x, y); annotation1.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot1.addAnnotation(annotation1); // II. Panel II = North // Use the first data array, within the plotted range (nstart - nend) to scale the plots: data = channelData.get(1); ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final NumberAxis verticalAxisN = new NumberAxis("Displacement (m)"); verticalAxisN.setRange(new Range(-ymax, ymax)); final XYSeriesCollection seriesCollection2 = new XYSeriesCollection(); seriesCollection2.addSeries(series[1]); seriesCollection2.addSeries(series[4]); seriesCollection2.addSeries(series[7]); final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, verticalAxisN, renderer); XYTextAnnotation annotation2 = new XYTextAnnotation("North-South", x, y); annotation2.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot2.addAnnotation(annotation2); // III. Panel III = East // Use the first data array, within the plotted range (nstart - nend) to scale the plots: data = channelData.get(2); ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final NumberAxis verticalAxisE = new NumberAxis("Displacement (m)"); verticalAxisE.setRange(new Range(-ymax, ymax)); final XYSeriesCollection seriesCollection3 = new XYSeriesCollection(); seriesCollection3.addSeries(series[2]); seriesCollection3.addSeries(series[5]); seriesCollection3.addSeries(series[8]); final XYPlot xyplot3 = new XYPlot((XYDataset) seriesCollection3, null, verticalAxisE, renderer); XYTextAnnotation annotation3 = new XYTextAnnotation("East-West", x, y); annotation3.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot3.addAnnotation(annotation3); //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL ); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.add(xyplot1, 1); combinedPlot.add(xyplot2, 1); combinedPlot.add(xyplot3, 1); combinedPlot.setGap(15.); final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 800); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:org.owasp.benchmark.score.report.ScatterTools.java
private void makeDataLabels(OverallResults or, XYPlot xyplot) { HashMap<Point2D, String> map = makePointList(or); for (Entry<Point2D, String> e : map.entrySet()) { if (e.getValue() != null) { Point2D p = e.getKey(); String label = sort(e.getValue()); XYTextAnnotation annotation = new XYTextAnnotation(label, p.getX(), p.getY()); annotation.setTextAnchor(p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER); annotation.setBackgroundPaint(Color.white); // set color of average to black and everything else to blue if (averageLabel == label.toCharArray()[0]) { annotation.setPaint(Color.magenta); } else { annotation.setPaint(Color.blue); }/*from w w w.ja v a 2 s . c o m*/ annotation.setFont(theme.getRegularFont()); xyplot.addAnnotation(annotation); } } }
From source file:org.owasp.benchmark.score.report.ScatterTools.java
private void makeLegend(OverallResults or, double x, double y, XYSeriesCollection dataset, XYPlot xyplot) { char ch = ScatterHome.INITIAL_LABEL; int i = 0;/* w w w .jav a 2 s . c o m*/ int toolCount = 0; double totalScore = 0; for (OverallResult r : or.getResults()) { toolCount++; // Special hack to make it line up better if the letter is an 'I' or 'i' String label = (ch == 'I' || ch == 'i' ? ch + ": " : "" + ch + ": "); double score = 100 * (r.truePositiveRate - r.falsePositiveRate); String msg = "\u25A0 " + label + r.category + " (" + Math.round(score) + "%)"; totalScore += score; XYTextAnnotation stroketext = new XYTextAnnotation(msg, x, y + i * -3.3); stroketext.setTextAnchor(TextAnchor.CENTER_LEFT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.blue); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); i++; // Weak hack if there are more than 26 tools scored. This will only get us to 52. if (ch == 'Z') ch = 'a'; else ch++; } if (toolCount > 1) { double averageScore = totalScore / toolCount; XYTextAnnotation stroketext = new XYTextAnnotation( "\u25A0 " + ch + ": Average Score for this Tool" + " (" + Math.round(averageScore) + "%)", x, y + i * -3.3); stroketext.setTextAnchor(TextAnchor.CENTER_LEFT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.magenta); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); Point2D averagePoint = new Point2D.Double(afpr * 100, atpr * 100); makePoint(xyplot, averagePoint, 3, Color.magenta); } }
From source file:org.fhcrc.cpl.viewer.ms2.gui.MS2ScanViewer.java
protected void buildChart() { if (scanInViewer == null) return;/*from w w w. java 2 s . com*/ if (chartInViewer != null) { remove(chartInViewer); } float[][] spectrum = scanInViewer.getSpectrum(); float[] mzValues = new float[spectrum[0].length]; float[] intensityValues = new float[spectrum[0].length]; for (int i = 0; i < mzValues.length; i++) { mzValues[i] = spectrum[0][i]; intensityValues[i] = spectrum[1][i]; } chartInViewer = new PanelWithPeakChart(mzValues, intensityValues, "ms2scan"); //add labels for highest peaks if (numHighestPeaksToLabel > 0) { XYPlot xyPlot = chartInViewer.getChart().getXYPlot(); List<Pair<Float, Float>> peaksAsPairs = new ArrayList<Pair<Float, Float>>(); for (int i = 0; i < mzValues.length; i++) peaksAsPairs.add(new Pair<Float, Float>(mzValues[i], intensityValues[i])); Collections.sort(peaksAsPairs, new Comparator<Pair<Float, Float>>() { @Override public int compare(Pair<Float, Float> pair1, Pair<Float, Float> pair2) { float diff = pair1.second - pair2.second; if (diff > 0) return -1; if (diff < 0) return 1; return 0; } }); for (int i = 0; i < numHighestPeaksToLabel; i++) { Pair<Float, Float> pair = peaksAsPairs.get(i); xyPlot.addAnnotation( new XYTextAnnotation("" + Rounder.round(pair.first, 3), pair.first, pair.second)); } } add(chartInViewer); updateUI(); }
From source file:com.bdb.weather.display.day.DayHumidityPane.java
@Override protected void addAnnotations(XYPlot plot, SummaryRecord summaryRecord) { plot.clearAnnotations();//w w w . jav a 2s. c o m if (summaryRecord == null) return; LocalDateTime highTime = summaryRecord.getMaxOutdoorHumidityTime(); Humidity highHumidity = summaryRecord.getMaxOutdoorHumidity(); LocalDateTime lowTime = summaryRecord.getMinOutdoorHumidityTime(); Humidity lowHumidity = summaryRecord.getMinOutdoorHumidity(); if (highTime == null || highHumidity == null || lowTime == null || lowHumidity == null) return; String highAnnotation = highHumidity.toString() + Humidity.Unit.RELATIVE_HUMIDITY + " " + DisplayConstants.formatTime(highTime.toLocalTime()); String lowAnnotation = lowHumidity.toString() + Humidity.Unit.RELATIVE_HUMIDITY + " " + DisplayConstants.formatTime(lowTime.toLocalTime()); XYTextAnnotation a = new XYTextAnnotation(highAnnotation, TimeUtils.localDateTimeToEpochMillis(highTime), highHumidity.get()); a.setTextAnchor(TextAnchor.BASELINE_CENTER); plot.addAnnotation(a); a = new XYTextAnnotation(lowAnnotation, TimeUtils.localDateTimeToEpochMillis(lowTime), lowHumidity.get()); a.setTextAnchor(TextAnchor.TOP_CENTER); plot.addAnnotation(a); }
From source file:org.owasp.benchmark.score.report.ScatterHome.java
private void makeDataLabels(Set<Report> toolResults, XYPlot xyplot) { HashMap<Point2D, String> map = makePointList(toolResults); for (Entry<Point2D, String> e : map.entrySet()) { if (e.getValue() != null) { Point2D p = e.getKey(); String label = sort(e.getValue()); XYTextAnnotation annotation = new XYTextAnnotation(label, p.getX(), p.getY()); annotation.setTextAnchor(p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER); annotation.setBackgroundPaint(Color.white); if (label.toCharArray()[0] == averageLabel) { annotation.setPaint(Color.magenta); } else { annotation.setPaint(Color.blue); }// w w w . j a va 2 s .c o m annotation.setFont(theme.getRegularFont()); xyplot.addAnnotation(annotation); } } }
From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java
/** * * @param fragments/*from www. j a v a2 s .c o m*/ * @param valueVar * @param useRT * @return */ public XYPlot provide1DPlot(List<IFileFragment> fragments, String valueVar, boolean useRT) { String[] labels = new String[fragments.size()]; Array[] arrays = new Array[fragments.size()]; Array[] domains = new Array[fragments.size()]; IFileFragment fragment = null; List<XYAnnotation> annotations = new ArrayList<>(); int i = 0; for (IFileFragment file : fragments) { fragment = file; labels[i] = fragment.getName() + " TIC"; arrays[i] = fragment.getChild(valueVar).getArray(); //Factory.getInstance().getConfiguration().getString("var.total_intensity","total_intensity")).getArray(); if (useRT) { try { domains[i] = fragment.getChild("scan_acquisition_time").getArray(); } catch (ResourceNotAvailableException rne) { } } // annotations.addAll(getANDIChromPeakAnnotations(fragment, useRT, valueVar)); // annotations.addAll(generatePeakShapes(fragment, useRT, new Color(0, // 0, 255, 192), new Color(0, 0, 255, 32), valueVar)); // annotations.addAll(getCSVPeakAnnotations(fragment, arrays[i], useRT)); //Factory.getInstance().getConfiguration().getString("var.scan_acquisition_time","scan_acquisition_time")).getArray(); i++; } XYChart xyc = null; if (useRT) { xyc = new XYChart(fragments.get(0).getName(), labels, arrays, domains, "time[s]", "value"); } else { xyc = new XYChart(fragments.get(0).getName(), labels, arrays, "index", "value"); } XYPlot xyp = xyc.create(); for (XYAnnotation xya : annotations) { xyp.addAnnotation(xya); } xyp.setRenderer(renderer); //xyp.setDomainCrosshairVisible(true); xyp.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset xyd, int i, int i1) { Comparable comp = xyd.getSeriesKey(i); double x = xyd.getXValue(i, i1); double y = xyd.getYValue(i, i1); StringBuilder sb = new StringBuilder(); sb.append(comp); sb.append(": "); sb.append("x="); sb.append(x); sb.append(" y="); sb.append(y); return sb.toString(); } }); // xyp.getRenderer().setDefaultEntityRadius(20); return xyp; }
From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java
/** * * @param fragments//from ww w . j a va 2 s . co m * @param masses * @param massResolution * @param useRT * @return */ public XYPlot provide1DEICCOPlot(List<IFileFragment> fragments, double[] masses, double massResolution, boolean useRT) { int i = 0; IFileFragment fragment; String[] labels = new String[fragments.size() * masses.length]; Array[] arrays = new Array[fragments.size() * masses.length]; Array[] domains = new Array[fragments.size() * masses.length]; double[] massValues = Arrays.copyOf(masses, masses.length); Arrays.sort(massValues); List<XYAnnotation> annotations = new ArrayList<>(); int trace = 0; for (IFileFragment file : fragments) { fragment = file; for (int k = 0; k < massValues.length; k++) { double minMZ = massValues[k]; double maxMZ = massValues[k] + massResolution; labels[trace] = fragment.getName() + " EICS:" + "[" + minMZ + "," + maxMZ + ")"; Array eic = MaltcmsTools.getEIC(fragment, minMZ, maxMZ, false, false); arrays[trace] = eic; if (useRT) { try { domains[trace] = fragment.getChild("scan_acquisition_time").getArray(); } catch (ResourceNotAvailableException rne) { } } trace++; } // annotations.addAll(getANDIChromPeakAnnotations(fragment, useRT)); // annotations.addAll(generatePeakShapes(fragment, useRT, new Color(0, // 0, 255, 192), new Color(0, 0, 255, 32))); // annotations.addAll(getCSVPeakAnnotations(fragment, arrays[i], useRT)); //Factory.getInstance().getConfiguration().getString("var.scan_acquisition_time","scan_acquisition_time")).getArray(); i++; } XYChart xyc = null; if (useRT) { xyc = new XYChart(fragments.get(0).getName(), labels, arrays, domains, "time[s]", "value"); } else { xyc = new XYChart(fragments.get(0).getName(), labels, arrays, "index", "value"); } XYPlot xyp = xyc.create(); for (XYAnnotation xya : annotations) { xyp.addAnnotation(xya); } xyp.setRenderer(renderer); xyp.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset xyd, int i, int i1) { Comparable comp = xyd.getSeriesKey(i); double x = xyd.getXValue(i, i1); double y = xyd.getYValue(i, i1); StringBuilder sb = new StringBuilder(); sb.append(comp); sb.append(": "); sb.append("x="); sb.append(x); sb.append(" y="); sb.append(y); return sb.toString(); } }); return xyp; }
From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java
/** * * @param fragments// w ww . j av a2 s . c om * @param masses * @param massResolution * @param useRT * @return */ public XYPlot provide1DEICSUMPlot(List<IFileFragment> fragments, double[] masses, double massResolution, boolean useRT) { int i = 0; IFileFragment fragment; String[] labels = new String[fragments.size()]; Array[] arrays = new Array[fragments.size()]; Array[] domains = new Array[fragments.size()]; double[] massValues = Arrays.copyOf(masses, masses.length); Arrays.sort(massValues); List<XYAnnotation> annotations = new ArrayList<>(); for (IFileFragment file : fragments) { fragment = file; StringBuilder mzRanges = new StringBuilder(); for (int k = 0; k < massValues.length; k++) { double minMZ = massValues[k]; double maxMZ = massValues[k] + massResolution; mzRanges.append("[" + minMZ + "," + maxMZ + ")"); if (k < massValues.length - 1) { mzRanges.append(","); } Array eic = MaltcmsTools.getEIC(fragment, minMZ, maxMZ, false, false); if (arrays[i] != null) { arrays[i] = MAMath.add(arrays[i], eic); } else { arrays[i] = eic; } //Factory.getInstance().getConfiguration().getString("var.total_intensity","total_intensity")).getArray(); } labels[i] = fragment.getName() + " EICS:" + mzRanges.toString(); if (useRT) { try { domains[i] = fragment.getChild("scan_acquisition_time").getArray(); } catch (ResourceNotAvailableException rne) { } } // annotations.addAll(getANDIChromPeakAnnotations(fragment, useRT)); // annotations.addAll(generatePeakShapes(fragment, useRT, new Color(0, // 0, 255, 192), new Color(0, 0, 255, 32))); // annotations.addAll(getCSVPeakAnnotations(fragment, arrays[i], useRT)); //Factory.getInstance().getConfiguration().getString("var.scan_acquisition_time","scan_acquisition_time")).getArray(); i++; } XYChart xyc = null; if (useRT) { xyc = new XYChart(fragments.get(0).getName(), labels, arrays, domains, "time[s]", "value"); } else { xyc = new XYChart(fragments.get(0).getName(), labels, arrays, "index", "value"); } XYPlot xyp = xyc.create(); for (XYAnnotation xya : annotations) { xyp.addAnnotation(xya); } // xyp.setDomainCrosshairVisible(true); xyp.setRenderer(renderer); xyp.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset xyd, int i, int i1) { Comparable comp = xyd.getSeriesKey(i); double x = xyd.getXValue(i, i1); double y = xyd.getYValue(i, i1); StringBuilder sb = new StringBuilder(); sb.append(comp); sb.append(": "); sb.append("x="); sb.append(x); sb.append(" y="); sb.append(y); return sb.toString(); } }); return xyp; }
From source file:mio_de_pso.MainForm.java
private void viewIndividuals(Individual[] population, XYPlot plot) { double annotationSize = (((x1Max - x1Min) * 0.02) + ((x2Max - x2Min) * 0.02)) / 2; for (int i = 0; i < population.length; ++i) { XYShapeAnnotation annotation = new XYShapeAnnotation( new Ellipse2D.Double(population[i].getPosition("x1"), population[i].getPosition("x2"), annotationSize, annotationSize), new BasicStroke(1.0f), Color.LIGHT_GRAY, Color.LIGHT_GRAY); plot.addAnnotation(annotation); }//from ww w . ja v a2 s .c o m }