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

📄 plot.java

📁 Differential Evolution(JAVA)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* A signal plotter.@Copyright (c) 1997-1998 The Regents of the University of California.All rights reserved.Permission is hereby granted, without written agreement and withoutlicense or royalty fees, to use, copy, modify, and distribute thissoftware and its documentation for any purpose, provided that theabove copyright notice and the following two paragraphs appear in allcopies of this software.IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTYFOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGESARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IFTHE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OFSUCH DAMAGE.THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWAREPROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OFCALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,ENHANCEMENTS, OR MODIFICATIONS.                                                PT_COPYRIGHT_VERSION_2                                                COPYRIGHTENDKEY*/package DeApp1.ptplot;// FIXME: To do//   - support for oscilloscope-like plots (where x axis wraps around).//   - steps between points rather than connected lines.//   - cubic spline interpolation//   - get rid of all of the deprecated lines and require JDK1.1//   - fix missing fill button under MacOS8.x/Netscape4.04//     // NOTE: The XOR drawing mode is needed in order to be able to erase// plotted points and restore the grid line, tick marks, and boundary// rectangle.  Another alternative would be to put the tick marks// outside the rectangle, disallow grid marks, and adjust drawing so// it never overlaps the boundary rectangle.  Then erasing could be// done by redrawing in white. This would be better.// NOTE: There are quite a few subjective spacing parameters, all// given, unfortunately, in pixels.  This means that as resolutions// get better, this program may need to be adjusted.import java.awt.*;import java.io.*;import java.util.*;////////////////////////////////////////////////////////////////////////////// Plot/**  * A flexible signal plotter.  The plot can be configured and data can * be provided either through a file with commands or through direct * invocation of the public methods of the class or by passing pxgraph * arguments through the "pxgraphargs" parameter.  If a file is used, * the file can be given as a URL through the <code>setDataurl</code> * method in the parent class.  The file contains any number commands, * one per line.  Unrecognized commands and commands with syntax * errors are ignored.  Comments are denoted by a line starting with a * pound sign "#".  The recognized commands include those supported by * the base class, plus a few more.  The commands are case * insensitive, but are usually capitalized.  The following command * defines the number of data sets to be plotted. * <pre> * NumSets: <i>positiveInteger</i> * </pre> * If data is provided for more data sets than this number, those * data are ignored.  Each dataset can be optionally identified with * color (see the base class) or with unique marks.  The style of * marks used to denote a data point is defined by one of the following * commands: * <pre> * Marks: none * Marks: points * Marks: dots * Marks: various * </pre> * Here, "points" are small dots, while "dots" are larger.  If "various" * is specified, then unique marks are used for the first ten data sets, * and then recycled. * Using no marks is useful when lines connect the points in a plot, * which is done by default.  To disable connecting lines, use: * <pre> * Lines: off * </pre> * To reenable them, use * <pre> * Lines: on * </pre> * You can also specify "impulses," which are lines drawn from a plotted point * down to the x axis.  These are off by default, but can be turned on with the * command: * <pre> * Impulses: on * </pre> * or back off with the command * <pre> * Impulses: off * </pre> * To create a bar graph, turn off lines and use any of the following commands: * <pre> * Bars: on * Bars: <i>width</i> * Bars: <i>width, offset</i> * </pre> * The <i>width</i> is a real number specifying the width of the bars * in the units of the x axis.  The <i>offset</i> is a real number * specifying how much the bar of the <i>i</i><sup>th</sup> data set * is offset from the previous one.  This allows bars to "peek out" * from behind the ones in front.  Note that the frontmost data set * will be the last one.  To turn off bars, use * <pre> * Bars: off * </pre> * To specify data to be plotted, start a data set with the following command: * <pre> * DataSet: <i>string</i> * </pre> * Here, <i>string</i> is a label that will appear in the legend. * It is not necessary to enclose the string in quotation marks. * If the following directive occurs: * <pre> * ReuseDataSets: on * </pre> * Then datasets with the same name will be merged.  This makes it * easier to combine multiple datafiles that contain the same datasets * into one file.  By default, this capability is turned off, so * datasets with the same name are not merged.  * The data itself is given by a sequence of commands with one of the * following forms: * <pre> * <i>x</i>,<i>y</i> * draw: <i>x</i>,<i>y</i> * move: <i>x</i>,<i>y</i> * <i>x</i>,<i>y</i>,<i>yLowErrorBar</i>,<i>yHighErrorBar</i> * </pre> * The "draw" command is optional, so the first two forms are equivalent. * The "move" command causes a break in connected points, if lines are * being drawn between points. The numbers <i>x</i> and <i>y</i> are * arbitrary numbers as supported by the Double parser in Java. * If there are four numbers, then the last two numbers are assumed to * be the lower and upper values for error bars. * The numbers can be separated by commas, spaces or tabs.  * * This plotter has some <A NAME="ptplot limitations">limitations</a>: * <ul> * <li> Marks, impulses, and bars are assumed to apply to the entire *      plot, i.e. to all data sets.  Although it is possible to change *      these styles for different data sets, the graph will not be *      correctly redrawn when it gets redrawn due to zooming in or out *      or due to a window exposure event. * <li> If you zoom in far enough, the plot becomes unreliable. *      In particular, if the total extent of the plot is more than *      2<sup>32</sup> times extent of the visible area, quantization *      errors can result in displaying points or lines. *      Note that 2<sup>32</sup> is over 4 billion. * <li> The limitations of the log axis facility are listed in *      the <code>_gridInit()</code> method in the PlotBox class. * <li> The compatibility issues of the <code>pxgraph</code> script are *      list in the *<a href="ptplot.Pxgraph.html#pxgraph script compatibility issues">Pxgraph</a>  *      class.  * </ul> * * @author Edward A. Lee, Christopher Hylands * @version @(#)Plot.java	1.93 05/07/98 */public class Plot extends PlotBox {

    /////////////////////////////////////////////////////////////////////////    ////                         public methods                          ////       /**     * In the specified data set, add the specified x,y point to the     * plot.  Data set indices begin with zero.  If the dataset     * argument is out of range, ignore.  The number of data sets is     * given by calling *setNumSets()*.  The fourth argument indicates     * whether the point should be connected by a line to the previous     * point.     */    public synchronized void addPoint(int dataset, double x, double y,            boolean connected) {        if (_xlog) {            if (x <= 0.0) {                System.err.println("Can't plot non-positive X values "+                        "when the logarithmic X axis value is specified: " +                        x);                return;            }            x = Math.log(x)*_LOG10SCALE;        }        if (_ylog) {            if (y <= 0.0) {                System.err.println("Can't plot non-positive Y values "+                        "when the logarithmic Y axis value is specified: " +                        y);                return;            }            y = Math.log(y)*_LOG10SCALE;        }        // This point is not an error bar so we set yLowEB        // and yHighEB to 0        _addPoint(_graphics, dataset, x, y, 0, 0, connected, false);    }        /**     * In the specified data set, add the specified x,y point to the     * plot with error bars.  Data set indices begin with zero.  If     * the dataset argument is out of range, ignore.  The number of     * data sets is given by calling *setNumSets()*.  yLowEB and     * yHighEB are the lower and upper error bars.  The sixth argument     * indicates whether the point should be connected by a line to     * the previous point.     * This method is based on a suggestion by     * Michael Altmann <michael@email.labmed.umn.edu>.     */    public synchronized void addPointWithErrorBars(int dataset,            double x, double y, double yLowEB, double yHighEB,            boolean connected) {        if (dataset >= _numsets || dataset < 0 || _datasetoverflow) return;        if (_xlog) {            if (x <= 0.0) {                System.err.println("Can't plot non-positive X values "+                        "when the logarithmic X axis value is specified: " +                        x);                return;            }            x = Math.log(x)*_LOG10SCALE;        }        if (_ylog) {            if (y <= 0.0 || yLowEB <= 0.0 || yHighEB <= 0.0) {                System.err.println("Can't plot non-positive Y values "+                        "when the logarithmic Y axis value is specified: " +                        y);                return;            }            y = Math.log(y)*_LOG10SCALE;            yLowEB = Math.log(yLowEB)*_LOG10SCALE;            yHighEB = Math.log(yHighEB)*_LOG10SCALE;        }        _addPoint(_graphics, dataset, x, y,                yLowEB, yHighEB, connected, true);    }        /**     * Draw the axes and then plot all points.  This is synchronized     * to prevent multiple threads from drawing the plot at the same     * time.  It calls <code>notify()</code> at the end so that a     * thread can use <code>wait()</code> to prevent it plotting     * points before the axes have been first drawn.  If the argument     * is true, clear the display first.     */    public synchronized void drawPlot(Graphics graphics,            boolean clearfirst) {        if (_debug > 7) System.out.println("Plot: drawPlot");        _calledDrawPlot = true;        // We must call PlotBox::drawPlot() before calling _drawPlotPoint        // so that _xscale and _yscale are set.        super.drawPlot(graphics, clearfirst);        // Plot the points        for (int dataset = 0; dataset < _numsets; dataset++) {            // FIXME: Make the following iteration more efficient.            Vector data = _points[dataset];            for (int pointnum = 0; pointnum < data.size(); pointnum++) {                _drawPlotPoint(graphics, dataset, pointnum);            }        }        notify();    }        /**      * Erase the point at the given index in the given dataset.  If     * lines are being drawn, also erase the line to the next points     * (note: not to the previous point).  The point is not checked to     * see whether it is in range, so care must be taken by the caller     * to ensure that it is.     */    public synchronized void erasePoint(int dataset, int index) {        _erasePoint(_graphics, dataset, index);      }    /**     * Return the maximum number of datasets     */    public int getMaxDataSets() {        return _MAX_DATASETS;    }    /**     * Initialize the plotter, parse any data files.     */    public synchronized void init() {
        if (_debug > 8) System.out.println("Plot: init");        setNumSets(_MAX_DATASETS);        super.init();        if (_dataurls != null ) {            // If the pxgraphargs parameter was set, then we might have more            // than one file to plot.            Enumeration urls = _dataurls.elements();            while (urls.hasMoreElements()) {                String url = (String) urls.nextElement();                if (_debug > 3) System.out.println("Plot: getting "+url);                parseFile(url);            }        }

⌨️ 快捷键说明

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