📄 contourplotdemo2.java
字号:
} this.yAxis.setLowerMargin(0.0); this.yAxis.setUpperMargin(0.0); if (!xIsDate) { this.xAxis.setRange(10.5, 15.0); } this.yAxis.setRange(3.5, 7.0); this.zColorBar.getAxis().setInverted(zIsInverted); this.zColorBar.getAxis().setTickMarksVisible(true); final ContourDataset data = createDataset(); final ContourPlot plot = new ContourPlot(data, this.xAxis, this.yAxis, this.zColorBar); if (xIsDate) { ratio = Math.abs(ratio); // don't use plot units for ratios when x axis is date } if (asPoints) { plot.setRenderAsPoints(true); } plot.setDataAreaRatio(ratio); if (annotate) { if (asPoints) { final Number[] xValues = data.getXValues(); final Number[] yValues = data.getYValues(); //Number[] zValues = data.getZValues(); final Font font = new Font("SansSerif", Font.PLAIN, 20); for (int i = 0; i < xValues.length; i++) { final XYTextAnnotation xyAnn = new XYTextAnnotation(Integer.toString(i), xValues[i].doubleValue(), yValues[i].doubleValue()); xyAnn.setFont(font); plot.addAnnotation(xyAnn); } } else { final Font font = new Font("SansSerif", Font.PLAIN, 20); for (int i = 0; i < this.tmpDoubleX.length; i++) { final XYTextAnnotation xyAnn = new XYTextAnnotation(Integer.toString(i), this.tmpDoubleX[i], this.tmpDoubleY[i]); xyAnn.setFont(font); plot.addAnnotation(xyAnn); } } } if (fillOutline || drawOutline) { initShoreline(); plot.setClipPath( new ClipPath(this.xOutline, this.yOutline, true, fillOutline, drawOutline) ); } final JFreeChart chart = new JFreeChart(title, null, plot, false); // then customise it a little... chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.green)); return chart; } /** * Creates a ContourDataset. * * @return ContourDataset. */ private ContourDataset createDataset() { initData(); final Double[] oDoubleX = (Double[]) DefaultContourDataset.formObjectArray(this.tmpDoubleX); final Double[] oDoubleY = (Double[]) DefaultContourDataset.formObjectArray(this.tmpDoubleY); final Double[] oDoubleZ = (Double[]) DefaultContourDataset.formObjectArray(this.tmpDoubleZ); final Date[] tmpDateX = new Date[this.tmpDoubleX.length]; for (int i = 0; i < this.tmpDoubleX.length; i++) { tmpDateX[i] = new Date((long) (1000.0 * this.tmpDoubleX[i])); } ContourDataset data = null; if (xIsDate) { if (asPoints) { data = new DefaultContourDataset("Contouring", tmpDateX, oDoubleY, oDoubleZ); } else { data = new NonGridContourDataset("Contouring", tmpDateX, oDoubleY, oDoubleZ); } } else if (!asPoints) { data = new NonGridContourDataset("Contouring", oDoubleX, oDoubleY, oDoubleZ, numX, numY, power); } else { data = new DefaultContourDataset("Contouring", oDoubleX, oDoubleY, oDoubleZ); } return data; } /** * Sets options passed via the command line * * @param args the arguments. * * @return Flag indicating whether program should continue. */ protected static boolean processArgs(final String[] args) { final String[] options = { "-?", "-date", "-vertical", "-points", "-outline", "-filled", "-ratio:", "-numX:", "-numY:", "-power:", "-annotate" }; for (int i = 0; i < args.length; i++) { boolean foundOption = false; for (int j = 0; j < options.length; j++) { if (args[i].startsWith(options[j])) { foundOption = true; int index = 0; String tmpStr = null; switch (j) { case 0: // -? usage(); return false; case 1: xIsDate = true; break; case 2: //zIsVertical = true; break; case 3: asPoints = true; break; case 4: drawOutline = true; break; case 5: fillOutline = true; break; case 6: index = args[i].indexOf(':'); tmpStr = args[i].substring(index + 1); ratio = Double.parseDouble(tmpStr); break; case 7: index = args[i].indexOf(':'); tmpStr = args[i].substring(index + 1); numX = Integer.parseInt(tmpStr); break; case 8: index = args[i].indexOf(':'); tmpStr = args[i].substring(index + 1); numY = Integer.parseInt(tmpStr); break; case 9: index = args[i].indexOf(':'); tmpStr = args[i].substring(index + 1); power = Integer.parseInt(tmpStr); break; case 10: annotate = true; break; default: System.out.println("Only 11 options available, update options array"); } } } if (!foundOption) { System.out.println("Unknown option: " + args[i]); usage(); return false; } } return true; // continue running application } /** * Prints usage options. */ public static void usage() { System.out.println("Usage:"); System.out.println("ContourPlotDemo2 -? -date -vertical -points -outline -filled " + "-ratio:value -numX:value -numY:value"); System.out.println("Where:"); System.out.println("-? displays usage and exits"); System.out.println("-date the X axis will be a date"); System.out.println("-vertical the colorbar will be drawn vertically"); System.out.println("-points demos plotting data as point (not grid)"); System.out.println("-outline draws shoreline outline and clips dataArea"); System.out.println("-filled fills shoreline and clips dataArea"); System.out.println("-ratio forces plot to maintain aspect ratio (Y/X) indicated by value"); System.out.println(" positive values are in pixels, while negative is in plot units"); System.out.println("-numX number of values to generate along the X axis"); System.out.println("-numY number of values to generate along the Y axis"); } /** * Starting point for the demonstration application. * * @param args command line options, launch ContourDemoPlot -? for listing of options. */ public static void main(final String[] args) { if (!processArgs(args)) { System.exit(1); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -