/** * 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); }
@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 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; }
/** * 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.setColor(color); canvas.add(plot);
plot.setColor(color); add(plot);