List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setSeriesLinesVisible
public void setSeriesLinesVisible(int series, boolean visible)
From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileGraphicDetailPanel.java
private void showCollection(XYSeriesCollection xyCollection, int shape, Color color) { if (null == indexMap.get(xyCollection)) { int index = registerCollectionOnPlot(xyCollection); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesLinesVisible(0, false); renderer2.setAutoPopulateSeriesShape(false); renderer2.setSeriesPaint(0, color); renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[shape]); xyp.setRenderer(index, renderer2); }/*ww w. ja va2 s. c om*/ }
From source file:csds60analyzer.csds60analyzerGUI.java
public BufferedImage creaImagen() { BufferedImage imagen = null;/*from w w w. ja v a 2s.c o m*/ try { SAXBuilder builder = new SAXBuilder(false); Document doc = null; TimeSeriesCollection datos = new TimeSeriesCollection(); if (fichero != null) { doc = builder.build(fichero); Element raiz = doc.getRootElement(); List<Element> dias = raiz.getChildren("dia"); Iterator<Element> diasIT = dias.iterator(); TimeSeries desayunoAntes = new TimeSeries("Desayuno antes"); TimeSeries desayunoDespues = new TimeSeries("Desayuno despus"); TimeSeries almuerzoAntes = new TimeSeries("Almuerzo antes"); TimeSeries almuerzoDespues = new TimeSeries("Almuerzo despus"); TimeSeries cenaAntes = new TimeSeries("Cena antes"); TimeSeries cenaDespues = new TimeSeries("Cena despus"); pdesayuno = 0; pdesant = 0; pdesdes = 0; palmuerzo = 0; palmant = 0; palmdes = 0; pcena = 0; pcenant = 0; pcendes = 0; contdesant = 0; contdesdes = 0; contalmant = 0; contalmdes = 0; contcenant = 0; contcendes = 0; while (diasIT.hasNext()) { Element diaActual = diasIT.next(); Integer fechaActual = Integer.parseInt(diaActual.getChildText("fecha").substring(0, 10)); Calendar fad = GregorianCalendar.getInstance(); fad.setTimeInMillis(fechaActual.longValue() * 1000); int dia = fad.get(Calendar.DAY_OF_MONTH); int mes = fad.get(Calendar.MONTH) + 1; int ano = fad.get(Calendar.YEAR); if (diaActual.getChildren().toString().contains("desayunoantes")) { int desayunoAntesActual = Integer.parseInt(diaActual.getChildText("desayunoantes")); desayunoAntes.add(new Day(dia, mes, ano), desayunoAntesActual); pdesant = pdesant + desayunoAntesActual; contdesant++; } if (diaActual.getChildren().toString().contains("desayunodespues")) { int desayunoDespuesActual = Integer.parseInt(diaActual.getChildText("desayunodespues")); desayunoDespues.add(new Day(dia, mes, ano), desayunoDespuesActual); pdesdes = pdesdes + desayunoDespuesActual; contdesdes++; } if (diaActual.getChildren().toString().contains("almuerzoantes")) { int almuerzoAntesActual = Integer.parseInt(diaActual.getChildText("almuerzoantes")); almuerzoAntes.add(new Day(dia, mes, ano), almuerzoAntesActual); palmant = palmant + almuerzoAntesActual; contalmant++; } if (diaActual.getChildren().toString().contains("almuerzodespues")) { int almuerzoDespuesActual = Integer.parseInt(diaActual.getChildText("almuerzodespues")); almuerzoDespues.add(new Day(dia, mes, ano), almuerzoDespuesActual); palmdes = palmdes + almuerzoDespuesActual; contalmdes++; } if (diaActual.getChildren().toString().contains("cenaantes")) { int cenaAntesActual = Integer.parseInt(diaActual.getChildText("cenaantes")); cenaAntes.add(new Day(dia, mes, ano), cenaAntesActual); pcenant = pcenant + cenaAntesActual; contcenant++; } if (diaActual.getChildren().toString().contains("cenadespues")) { int cenaDespuesActual = Integer.parseInt(diaActual.getChildText("cenadespues")); cenaDespues.add(new Day(dia, mes, ano), cenaDespuesActual); pcendes = pcendes + cenaDespuesActual; contcendes++; } } //controlar la division por cero if ((contdesant + contdesdes) > 0) pdesayuno = (pdesant + pdesdes) / (contdesant + contdesdes); if (contdesant > 0) pdesant = pdesant / contdesant; if (contdesdes > 0) pdesdes = pdesdes / contdesdes; if ((contalmant + contalmdes) > 0) palmuerzo = (palmant + palmdes) / (contalmant + contalmdes); if (contalmant > 0) palmant = palmant / contalmant; if (contalmdes > 0) palmdes = palmdes / contalmdes; if ((contcenant + contcendes) > 0) pcena = (pcenant + pcendes) / (contcenant + contcendes); if (contcenant > 0) pcenant = pcenant / contcenant; if (contcendes > 0) pcendes = pcendes / contcendes; datos.addSeries(desayunoAntes); datos.addSeries(desayunoDespues); datos.addSeries(almuerzoAntes); datos.addSeries(almuerzoDespues); datos.addSeries(cenaAntes); datos.addSeries(cenaDespues); } JFreeChart graficaJfree = ChartFactory.createTimeSeriesChart("Anlisis", " ", "Glucosa (mg)", datos, true, true, false); XYPlot plot = (XYPlot) graficaJfree.getPlot(); plot.setBackgroundPaint(Color.getHSBColor(0f, 0f, .88f)); plot.setDomainGridlinePaint(Color.getHSBColor(0f, 0f, .35f)); plot.setDomainTickBandPaint(Color.getHSBColor(0f, 0f, .93f)); plot.setOutlinePaint(Color.getHSBColor(0f, 0f, 0.35f)); plot.setRangeGridlinePaint(Color.getHSBColor(0f, 0f, 0.35f)); XYLineAndShapeRenderer plot2 = (XYLineAndShapeRenderer) plot.getRenderer(); if (!CBdesayunoantes.getState()) plot2.setSeriesLinesVisible(0, false); plot2.setSeriesPaint(0, Color.getHSBColor(.3f, 1f, .5f)); //plot2.setSeriesStroke(0,new BasicStroke(2.0f,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND,1.0f)); if (!CBdesayunodespues.getState()) plot2.setSeriesLinesVisible(1, false); plot2.setSeriesPaint(1, Color.getHSBColor(.2f, 1f, .9f)); if (!CBalmuerzoantes.getState()) plot2.setSeriesLinesVisible(2, false); plot2.setSeriesPaint(2, Color.getHSBColor(.0f, 1f, .6f)); if (!CBalmuerzodespues.getState()) plot2.setSeriesLinesVisible(3, false); plot2.setSeriesPaint(3, Color.getHSBColor(.0f, 1f, .9f)); if (!CBcenaantes.getState()) plot2.setSeriesLinesVisible(4, false); plot2.setSeriesPaint(4, Color.getHSBColor(.6f, 1f, .4f)); if (!CBcenadespues.getState()) plot2.setSeriesLinesVisible(5, false); plot2.setSeriesPaint(5, Color.getHSBColor(.6f, 1f, 1f)); imagen = graficaJfree.createBufferedImage(800, 600); } catch (Exception e) { e.printStackTrace(); } return imagen; }
From source file:jmeanshift.ChartProof.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed dataset.removeAllSeries();//from w w w.j a v a2 s .co m Vector<Vector> vdataset = new Vector<Vector>(); vdataset.add(data1); vdataset.add(data2); // dataset.add(data3); //dataset.add(data4); System.out.print("["); for (int k = 0; k < data1.size(); k++) { System.out.print(" " + data1.get(k)); } System.out.print(" ]"); System.out.print("\n"); System.out.print("["); for (int k = 0; k < data1.size(); k++) { System.out.print(" " + data2.get(k)); } System.out.print(" ]"); System.out.print("\n"); MeanShift domean = new MeanShift(); double criteria = Double.parseDouble(jTextField1.getText().trim()); double band = Double.parseDouble(jTextField2.getText().trim()); domean.setMergeClusters(jcbMergeClusters.isSelected()); domean.doMeanShift(vdataset, band, criteria, jcbRandomMode.isSelected()); XYSeries[] clusters = new XYSeries[domean.getkClusters()]; XYSeries[] clustersCenter = new XYSeries[domean.getkClusters()]; XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); //varre o numero de cluster for (int y = 0; y < domean.getkClusters(); y++) { clustersCenter[y] = new XYSeries("center " + y); dataset.addSeries(clustersCenter[y]); clusters[y] = new XYSeries("cluster " + y); dataset.addSeries(clusters[y]); double[] cc = domean.clusterCenter.get(y); clustersCenter[y].add(cc[0], cc[1]); renderer.setSeriesLinesVisible(dataset.getSeriesCount() - 2, Boolean.FALSE); renderer.setSeriesLinesVisible(dataset.getSeriesCount() - 1, Boolean.FALSE); renderer.setSeriesShape(dataset.getSeriesCount() - 2, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0)); renderer.setSeriesShape(dataset.getSeriesCount() - 1, new Ellipse2D.Double(-2.0, -2.0, 3.0, 3.0)); renderer.setSeriesShapesFilled(dataset.getSeriesCount() - 2, Boolean.TRUE); renderer.setSeriesShapesFilled(dataset.getSeriesCount() - 1, Boolean.TRUE); for (int k = 0; k < domean.clustersMembers.size(); k++) { if (y == domean.clustersMembers.get(k)) { clusters[y].add(data1.get(k), data2.get(k)); //System.out.println("y: " + y + " x1: " +series.getX(k)+ " x2: "+series.getY(k)); } } } plot.setRenderer(renderer); }
From source file:asl.util.PlotMaker.java
public void plotCoherence(double per[], double[] gamma, String plotString) { final String plotTitle = String.format("%04d%03d.%s.%s-%s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channelX, channelY); final String pngName = String.format("%s/%04d%03d.%s.%s-%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channelX, channelY, 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("== plotCoherence: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return;/*from w w w .ja v a2 s . c o m*/ } final String legend = String.format("%s--%s", channelX, channelY); final XYSeries series1 = new XYSeries(legend); for (int k = 0; k < gamma.length; k++) { series1.add(per[k], gamma[k]); } //final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer1.setSeriesShape(0, rectangle); renderer1.setSeriesShapesVisible(0, true); renderer1.setSeriesLinesVisible(0, false); Paint[] paints = new Paint[] { Color.red, Color.black }; renderer1.setSeriesPaint(0, paints[0]); final NumberAxis rangeAxis1 = new NumberAxis("Coherence, Gamma"); rangeAxis1.setRange(new Range(0, 1.2)); rangeAxis1.setTickUnit(new NumberTickUnit(0.1)); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Period (sec)"); horizontalAxis.setRange(new Range(0.05, 10000)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, horizontalAxis, rangeAxis1, renderer1); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final JFreeChart chart = new JFreeChart(xyplot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:edu.ucla.stat.SOCR.analyses.gui.Chart.java
private JFreeChart createLineAndDotChart(String title, String xLabel, String yLabel, XYDataset dataset, int numberOfLines, Color[] lineColors, int numberOfDotsGroups, Color[] dotColors, String other) { boolean legend = true; if (other.toLowerCase().indexOf("noledend") != -1) { legend = false;/*from www.j a va 2s . c o m*/ } // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation legend, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); chart.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setDomainGridlinePaint(Color.lightGray); //plot.setNoDataMessage("No data available"); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.02); rangeAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setLowerMargin(0.02); // customise the renderer... XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < numberOfLines; i++) { renderer.setSeriesShapesVisible(i, false); renderer.setSeriesLinesVisible(i, true); } for (int i = numberOfLines; i < numberOfLines + numberOfDotsGroups; i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesLinesVisible(i, false); } // renderer.setDrawOutlines(true); // renderer.setBaseShapesFilled(true); // renderer.setUseFillPaint(true); // renderer.setFillPaint(Color.white); //set line color for (int i = 0; i < lineColors.length; i++) { renderer.setSeriesPaint(i, lineColors[i]); } // set dot color for (int i = 0; i < dotColors.length; i++) { renderer.setSeriesPaint(numberOfLines + i, dotColors[i]); } if (other.toLowerCase().indexOf("excludeszero") != -1) { rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setAutoRangeIncludesZero(false); } return chart; }
From source file:edu.ucla.stat.SOCR.analyses.gui.Chart.java
protected JFreeChart createQQChart(String title, String xLabel, String yLabel, XYDataset dataset, String other) {/* w w w . j a v a 2s . co m*/ // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title xLabel, // x axis label yLabel, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); // renderer.setShapesVisible(true); renderer.setBaseShapesFilled(true); // renderer.setLinesVisible(false); renderer.setSeriesLinesVisible(1, true); renderer.setSeriesShapesVisible(1, false); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); //renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setUpperMargin(0.02); rangeAxis.setLowerMargin(0.02); // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setUpperMargin(0.02); domainAxis.setLowerMargin(0.02); // domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. //setQQSummary(dataset); // very confusing return chart; }
From source file:asl.util.PlotMaker.java
public void plotPSD(double per[], double[] model, double[] nhnmPer, double[] nhnm, double[] psd, String modelName, String plotString) { // plotTitle = "2012074.IU_ANMO.00-BHZ " + plotString final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); // plot filename = "2012074.IU_ANMO.00-BHZ" + plotString + ".png" final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, 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(/* w ww . j a v a2 s.c o m*/ "== plotPSD: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return; } Boolean plotNHNM = false; //if (nhnm.length > 0) { if (nhnm != null) { plotNHNM = true; } final XYSeries series1 = new XYSeries(modelName); final XYSeries series2 = new XYSeries(channel.toString()); final XYSeries series3 = new XYSeries("NHNM"); for (int k = 0; k < per.length; k++) { series1.add(per[k], model[k]); series2.add(per[k], psd[k]); } if (plotNHNM) { for (int k = 0; k < nhnmPer.length; k++) { series3.add(nhnmPer[k], nhnm[k]); } } //final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer.setSeriesShape(0, rectangle); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShape(1, rectangle); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShape(2, rectangle); renderer.setSeriesShapesVisible(2, false); renderer.setSeriesLinesVisible(2, true); Paint[] paints = new Paint[] { Color.blue, Color.red, Color.black }; renderer.setSeriesPaint(0, paints[0]); renderer.setSeriesPaint(1, paints[1]); renderer.setSeriesPaint(2, paints[2]); final NumberAxis rangeAxis1 = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB"); //rangeAxis1.setRange( new Range(-190, -120)); rangeAxis1.setRange(new Range(-190, -95)); rangeAxis1.setTickUnit(new NumberTickUnit(5.0)); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Period (sec)"); horizontalAxis.setRange(new Range(0.05, 10000)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); seriesCollection.addSeries(series2); if (plotNHNM) { seriesCollection.addSeries(series3); } final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, horizontalAxis, rangeAxis1, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final JFreeChart chart = new JFreeChart(xyplot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:projects.wdlf47tuc.ProcessAllSwathcal.java
/** * Plots the CMD using the existing dataset. Used whenever chart annotations change, without the * underlying plot data changing. This method identifies all sources lying within the boxed region * and loads them into the secondary list {@link #boxedSources}. * //from ww w . j av a 2 s . c o m * @param allSources * The {@link Source}s to plot * @return * A JFreeChart presenting the colour-magnitude diagram for the current selection criteria and colours. */ private JFreeChart plotCmd() { XYSeries outside = new XYSeries("Outside"); XYSeries inside = new XYSeries("Inside"); // Use a Path2D.Double instance to determine polygon intersection Path2D.Double path = new Path2D.Double(); boxedSources.clear(); boolean performBoxSelection = (points.size() > 2); if (performBoxSelection) { // Initialise Path2D object path.moveTo(points.get(0)[0], points.get(0)[1]); for (double[] point : points) { path.lineTo(point[0], point[1]); } } for (Source source : selectedSources) { double magnitude = source.getMag(magFilter); double col1 = source.getMag(col1Filter); double col2 = source.getMag(col2Filter); double x = col1 - col2; double y = magnitude; if (performBoxSelection) { Point2D.Double point = new Point2D.Double(x, y); if (path.contains(point)) { inside.add(x, y); boxedSources.add(source); } else { outside.add(x, y); } } else { outside.add(x, y); } } final XYSeriesCollection data = new XYSeriesCollection(); data.addSeries(outside); data.addSeries(inside); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShape(0, new Ellipse2D.Float(-0.5f, -0.5f, 1, 1)); renderer.setSeriesPaint(0, ChartColor.BLACK); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesShape(1, new Ellipse2D.Float(-0.5f, -0.5f, 1, 1)); renderer.setSeriesPaint(1, ChartColor.RED); NumberAxis xAxis = new NumberAxis(col1Filter.toString() + " - " + col2Filter.toString()); xAxis.setRange(getXRange()); NumberAxis yAxis = new NumberAxis(magFilter.toString()); yAxis.setRange(getYRange()); yAxis.setInverted(true); // Configure plot XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.white); // Specify selection box, if points have been specified if (!points.isEmpty()) { double[] coords = new double[points.size() * 2]; for (int i = 0; i < points.size(); i++) { double[] point = points.get(i); coords[2 * i + 0] = point[0]; coords[2 * i + 1] = point[1]; } XYPolygonAnnotation box = new XYPolygonAnnotation(coords, new BasicStroke(2.0f), Color.BLUE); xyplot.addAnnotation(box); } // Configure chart JFreeChart chart = new JFreeChart("47 Tuc CMD", xyplot); chart.setBackgroundPaint(Color.white); chart.setTitle("47 Tuc colour-magnitude diagram"); chart.removeLegend(); return chart; }
From source file:asl.util.PlotMaker.java
public void plotSpecAmp(double freq[], double[] amp, double[] phase, String plotString) { // plotTitle = "2012074.IU_ANMO.00-BHZ " + plotString final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); // plot filename = "2012074.IU_ANMO.00-BHZ" + plotString + ".png" final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, 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("== plotSpecAmp: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return;//from w ww .j ava 2s . c om } final XYSeries series1 = new XYSeries("Amplitude"); final XYSeries series2 = new XYSeries("Phase"); double maxdB = 0.; for (int k = 0; k < freq.length; k++) { double dB = 20. * Math.log10(amp[k]); series1.add(freq[k], dB); series2.add(freq[k], phase[k]); if (dB > maxdB) { maxdB = dB; } } //final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer.setSeriesShape(0, rectangle); //renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShape(1, rectangle); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(1, false); Paint[] paints = new Paint[] { Color.red, Color.blue }; renderer.setSeriesPaint(0, paints[0]); //renderer.setSeriesPaint(1, paints[1]); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesPaint(0, paints[1]); renderer2.setSeriesShapesVisible(0, false); renderer2.setSeriesLinesVisible(0, true); // Stroke is part of Java Swing ... //renderer2.setBaseStroke( new Stroke( ... ) ); double ymax; if (maxdB < 10) { ymax = 10.; } else { ymax = maxdB + 2; ; } final NumberAxis verticalAxis = new NumberAxis("Spec Amp (dB)"); verticalAxis.setRange(new Range(-40, ymax)); verticalAxis.setTickUnit(new NumberTickUnit(5)); //final LogarithmicAxis verticalAxis = new LogarithmicAxis("Amplitude Response"); //verticalAxis.setRange( new Range(0.01 , 10) ); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Frequency (Hz)"); //horizontalAxis.setRange( new Range(0.0001 , 100.5) ); horizontalAxis.setRange(new Range(0.00009, 110)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, null, verticalAxis, renderer); //final XYPlot xyplot = new XYPlot((XYDataset)seriesCollection, horizontalAxis, verticalAxis, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final NumberAxis phaseAxis = new NumberAxis("Phase (Deg)"); phaseAxis.setRange(new Range(-180, 180)); phaseAxis.setTickUnit(new NumberTickUnit(30)); final XYSeriesCollection seriesCollection2 = new XYSeriesCollection(); seriesCollection2.addSeries(series2); final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, phaseAxis, renderer2); //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL ); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.add(xyplot, 1); combinedPlot.add(xyplot2, 1); combinedPlot.setGap(15.); //final JFreeChart chart = new JFreeChart(xyplot); final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle)); // Here we need to see if test dir exists and create it if necessary ... try { //ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300); //ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300); ChartUtilities.saveChartAsPNG(outputFile, chart, 1000, 800); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
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;// w w w . j a v a 2s . c om } 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."); } }