/** * Create a plot canvas with the bar plot of given data. * @param id the id of the plot. * @param data a n x 2 matrix of which data[][0] determine the location of * bars and data[][1] determine the heights of bars. data[][0] will also be * used as the labels. For best view, data[][0] should be monotonic. */ public static PlotCanvas plot(String id, double[]... data) { if (data[0].length != 2) { throw new IllegalArgumentException("Dataset is not 2-dimensional."); } double[] lowerBound = Math.colMin(data); double[] upperBound = Math.colMax(data); PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound); canvas.getAxis(0).setGridVisible(false); BarPlot plot = new BarPlot(data); plot.setID(id); canvas.add(plot); return canvas; } }
/** * Create a plot canvas with the bar plot of given data. * @param id the id of the plot. * @param data a vector of which values will determine the heights of bars. * @param labels the labels for each bar. */ public static PlotCanvas plot(String id, double[] data, String[] labels) { if (data.length != labels.length) { throw new IllegalArgumentException("Data size and label size don't match."); } double[] lowerBound = {0, Math.min(data)}; double[] upperBound = {data.length, Math.max(data)}; PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound); BarPlot plot = new BarPlot(labels, data); plot.setID(id); canvas.add(plot); double[] locations = new double[labels.length]; for (int i = 0; i < labels.length; i++) { locations[i] = i + 0.5; } canvas.getAxis(0).addLabel(labels, locations); canvas.getAxis(0).setGridVisible(false); return canvas; }
/** * Create a plot canvas with the bar plot of given data. * @param id the id of the plot. * @param data a vector of which values will determine the heights of bars. */ public static PlotCanvas plot(String id, double[] data) { double[] lowerBound = {0, Math.min(data)}; double[] upperBound = {data.length, Math.max(data)}; PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound); BarPlot plot = new BarPlot(data); plot.setID(id); canvas.add(plot); canvas.getAxis(0).setGridVisible(false); canvas.getAxis(0).setLabelVisible(false); return canvas; }