/** * Create a plot canvas with the scatter plot of given data. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of n points. * @param labels labels of points. */ public static PlotCanvas plot(double[][] data, String[] labels) { return plot(null, data, labels); }
@Override public void paint(Graphics g) { line.paint(g); if (drawDot) { super.paint(g); } }
/** * Constructor. * @param data The array of data to plot. The elements should be of dimension 2 or 3. * @param y The class label of each data point of size n, where n is the size of data. * @param legends The legend of each class, of size k, where k is the amount of unique values in y. * @param color The color of all data points. */ public ScatterPlot(double[][] data, int[] y, char[] legends, Color color) { this(data, y, legends, (Color[]) null); setColor(color); }
/** * Create a plot canvas with the scatter plot of given data. * @param id the id of the plot. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of n points. */ public static PlotCanvas plot(String id, double[]... data) { if (data[0].length != 2 && data[0].length != 3) { throw new IllegalArgumentException("Invalid data dimension: " + data[0].length); } double[] lowerBound = Math.colMin(data); double[] upperBound = Math.colMax(data); PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound); ScatterPlot plot = new ScatterPlot(data); plot.setID(id); canvas.add(plot); return canvas; }
/** * Create a plot canvas with the scatter plot of given data and specific color. * @param id the id of the plot. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points. * @param color the color used to draw points. */ public static PlotCanvas plot(String id, double[][] data, Color color) { if (data[0].length != 2 && data[0].length != 3) { throw new IllegalArgumentException("Invalid data dimension: " + data[0].length); } double[] lowerBound = Math.colMin(data); double[] upperBound = Math.colMax(data); PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound); ScatterPlot plot = new ScatterPlot(data); plot.setID(id); plot.setColor(color); canvas.add(plot); return canvas; }
/** * Plot plot. * * @param pts the pts * @return the plot */ public Plot plot(final double[][] pts) { Plot plot; switch (type) { case Scatter: plot = new ScatterPlot(pts); plot.setID(name); plot.setColor(color); return plot; case Line: plot = new LinePlot(pts); plot.setID(name); plot.setColor(color); return plot; default: throw new IllegalStateException(type.toString()); } }
@Override public LinePlot setLegend(char legend) { super.setLegend(legend); drawDot = true; return this; }
@Override public void paint(Graphics g) { Color c = g.getColor(); g.setColor(getColor()); if (labels != null) { for (int i = 0; i < data.length; i++) { g.drawText(labels[i], data[i]); } } else { if (y == null) { for (int i = 0; i < data.length; i++) { g.drawPoint(legend, data[i]); } } else { for (int i = 0; i < data.length; i++) { if (palette != null) { g.setColor(palette[classLookupTable.get(y[i])]); } if (legends != null) { g.drawPoint(legends[classLookupTable.get(y[i])], data[i]); } else { g.drawPoint(legend, data[i]); } } } } g.setColor(c); }
/** * Create a plot canvas with the scatter plot of given data. * @param id the id of the plot. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of n points. * @param labels labels of points. */ public static PlotCanvas plot(String id, double[][] data, String[] labels) { if (data[0].length != 2 && data[0].length != 3) { throw new IllegalArgumentException("Invalid data dimension: " + data[0].length); } if (data.length != labels.length) { throw new IllegalArgumentException("The number of points and that of labels are not same."); } double[] lowerBound = Math.colMin(data); double[] upperBound = Math.colMax(data); PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound); ScatterPlot plot = new ScatterPlot(data, labels); plot.setID(id); canvas.add(plot); return canvas; }
/** * Adds a scatter plot to this canvas. * @param id the id of the plot. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points. * @param color the color used to draw points. * @return the scatter plot for the given points. */ public ScatterPlot points(String id, double[][] data, Color color) { if (data[0].length != base.dimension) { throw new IllegalArgumentException("Invalid data dimension: " + data[0].length); } double[] lowerBound = Math.colMin(data); double[] upperBound = Math.colMax(data); extendBound(lowerBound, upperBound); ScatterPlot plot = new ScatterPlot(data); plot.setID(id); plot.setColor(color); add(plot); return plot; }
/** * Plot plot. * * @param pts the pts * @return the plot */ public Plot plot(final double[][] pts) { Plot plot; switch (type) { case Scatter: plot = new ScatterPlot(pts); plot.setID(name); plot.setColor(color); return plot; case Line: plot = new LinePlot(pts); plot.setID(name); plot.setColor(color); return plot; default: throw new IllegalStateException(type.toString()); } }
/** * Create a plot canvas with the scatter plot of given data and specific color. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points. * @param color the color used to draw points. */ public static PlotCanvas plot(double[][] data, Color color) { return plot(null, data, color); }
/** * Adds a scatter plot to this canvas. * @param id the id of the plot. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points. * @return the scatter plot for the given points. */ public ScatterPlot points(String id, double[]... data) { if (data[0].length != base.dimension) { throw new IllegalArgumentException("Invalid data dimension: " + data[0].length); } double[] lowerBound = Math.colMin(data); double[] upperBound = Math.colMax(data); extendBound(lowerBound, upperBound); ScatterPlot plot = new ScatterPlot(data); plot.setID(id); add(plot); return plot; }
extendBound(lowerBound, upperBound); ScatterPlot plot = new ScatterPlot(data, legend); plot.setID(id); plot.setColor(color); add(plot);
/** * Plot plot. * * @param pts the pts * @return the plot */ public Plot plot(final double[][] pts) { Plot plot; switch (type) { case Scatter: plot = new ScatterPlot(pts); plot.setID(name); plot.setColor(color); return plot; case Line: plot = new LinePlot(pts); plot.setID(name); plot.setColor(color); return plot; default: throw new IllegalStateException(type.toString()); } }
@Override public LinePlot setColor(Color color) { super.setColor(color); line.setColor(color); return this; }
/** * Create a plot canvas with the scatter plot of given data. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of n points. */ public static PlotCanvas plot(double[]... data) { return plot(null, data); }
/** * Adds a scatter plot to this canvas. * @param id the id of the plot. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points. * @param labels labels of points. * @return the scatter plot for the given points. */ public ScatterPlot points(String id, double[][] data, String[] labels) { if (data[0].length != base.dimension) { throw new IllegalArgumentException("Invalid data dimension: " + data[0].length); } if (data.length != labels.length) { throw new IllegalArgumentException("The number of points and that of labels are not same."); } double[] lowerBound = Math.colMin(data); double[] upperBound = Math.colMax(data); extendBound(lowerBound, upperBound); ScatterPlot plot = new ScatterPlot(data, labels); plot.setID(id); add(plot); return plot; }
PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound); ScatterPlot plot = new ScatterPlot(data, legend); plot.setID(id); plot.setColor(color); canvas.add(plot);
/** * Create a plot canvas with the scatter plot of given data with specific legend. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points. * @param legend the legend used to draw points. * <ul> * <li> . : dot * <li> + : + * <li> - : - * <li> | : | * <li> * : star * <li> x : x * <li> o : circle * <li> O : large circle * <li> @ : solid circle * <li> # : large solid circle * <li> s : square * <li> S : large square * <li> q : solid square * <li> Q : large solid square * <li> others : dot * </ul> */ public static PlotCanvas plot(double[][] data, char legend) { return plot(null, data, legend); }