⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contourplotdemo2.java

📁 大家打开看看啊, 很有用的东西
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }

        yAxis.setLowerMargin(0.0);
        yAxis.setUpperMargin(0.0);

        if (!xIsDate) {
            xAxis.setRange(10.5, 15.0);
        } 
        yAxis.setRange(3.5, 7.0);

        zColorBar.getAxis().setInverted(zIsInverted);
        zColorBar.getAxis().setTickMarksVisible(true);

        ContourDataset data = createDataset();

        ContourPlot plot = new ContourPlot(data, xAxis, yAxis, 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) {
                Number[] xValues = data.getXValues();
                Number[] yValues = data.getYValues();
                //Number[] zValues = data.getZValues();

                Font font = new Font("SansSerif", Font.PLAIN, 20);

                for (int i = 0; i < xValues.length; i++) {
                    XYTextAnnotation xyAnn = new XYTextAnnotation(Integer.toString(i),
                                               xValues[i].doubleValue(), yValues[i].doubleValue());
                    xyAnn.setFont(font);
                    plot.addAnnotation(xyAnn);
                }
            } 
            else {
                Font font = new Font("SansSerif", Font.PLAIN, 20);

                for (int i = 0; i < tmpDoubleX.length; i++) {
                    XYTextAnnotation xyAnn = new XYTextAnnotation(Integer.toString(i),
                                                                  tmpDoubleX[i], tmpDoubleY[i]);
                    xyAnn.setFont(font);
                    plot.addAnnotation(xyAnn);
                }
            }

        }

        if (fillOutline || drawOutline) {
            initShoreline();
            plot.setClipPath(new ClipPath(xOutline, yOutline, true, fillOutline, drawOutline));
        }

        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();

        Double[] oDoubleX = (Double[]) DefaultContourDataset.formObjectArray(tmpDoubleX);
        Double[] oDoubleY = (Double[]) DefaultContourDataset.formObjectArray(tmpDoubleY);
        Double[] oDoubleZ = (Double[]) DefaultContourDataset.formObjectArray(tmpDoubleZ);

        Date[] tmpDateX = new Date[tmpDoubleX.length];
        for (int i = 0; i < tmpDoubleX.length; i++) {
            tmpDateX[i] = new Date((long) (1000.0 * 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(String[] args) {
        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(String[] args) {

        if (!processArgs(args)) {
            System.exit(1);
        }
        ContourPlotDemo2 demo = new ContourPlotDemo2("ContourPlot Demo");
        demo.pack();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -