/** Prepares a new PlotContentsDialog for creating a new plot using float[] arrays as data. * Each 'data' array in the ArrayList must have a corresponding element in the 'headings' array. * 'defaultHeadings' may contain the headings of the items selected initially for x, y, x error and y error, respectively. * 'defaultHeadings' and each of its entries may be null, and the array may have any length. */ public PlotContentsDialog(String title, String[] headings, String[] defaultHeadings, ArrayList<float[]> data) { creatingPlot = true; dialogType = ADD_FROM_ARRAYS; this.arrayHeadings = headings; this.arrayData = data; plot = new Plot(title, "x", "y"); setDefaultColumns(defaultHeadings); }
/** Prepares a new PlotContentsDialog for creating a new plot using float[] arrays as data. * Each 'data' array in the ArrayList must have a corresponding element in the 'headings' array. * 'defaultHeadings' may contain the headings of the items selected initially for x, y, x error and y error, respectively. * 'defaultHeadings' and each of its entries may be null, and the array may have any length. */ public PlotContentsDialog(String title, String[] headings, String[] defaultHeadings, ArrayList<float[]> data) { creatingPlot = true; dialogType = ADD_FROM_ARRAYS; this.arrayHeadings = headings; this.arrayData = data; plot = new Plot(title, "x", "y"); setDefaultColumns(defaultHeadings); }
/** Called by the constructor to generate the image the plot will be drawn on. This is a static method because constructors cannot call instance methods. */ static ImagePlus createImage(String title, String xLabel, String yLabel, float[] xValues, float[] yValues) { staticPlot = new Plot(title, xLabel, yLabel, xValues, yValues); return new ImagePlus(title, staticPlot.getBlankProcessor()); }
/** Prepares a new PlotContentsDialog for creating a new plot using data from a ResultsTable. * Use showDialog thereafter. */ public PlotContentsDialog(String title, ResultsTable rt) { creatingPlot = true; dialogType = ADD_FROM_TABLE; if (rt == null || !isValid(rt)) { IJ.error("Cant Create Plot","No (results) table or no data in "+title); dialogType = ERROR; } plot = new Plot("Plot of "+title, "x", "y"); allTables = new ResultsTable[] {rt}; allTableNames = new String[] {title}; }
/** Called by the constructor to generate the image the plot will be drawn on. This is a static method because constructors cannot call instance methods. */ static ImagePlus createImage(String title, String xLabel, String yLabel, float[] xValues, float[] yValues) { staticPlot = new Plot(title, xLabel, yLabel, xValues, yValues); return new ImagePlus(title, staticPlot.getBlankProcessor()); }
public void plot2d() { JGnuplot jg = new JGnuplot(); Plot plot = new Plot("") { { xlabel = "x"; ylabel = "y"; } }; double[] x = { 1, 2, 3, 4, 5 }, y1 = { 2, 4, 6, 8, 10 }, y2 = { 3, 6, 9, 12, 15 }; DataTableSet dts = plot.addNewDataTableSet("2D Plot"); dts.addNewDataTable("y=2x", x, y1); dts.addNewDataTable("y=3x", x, y2); jg.execute(plot, jg.plot2d); }
/** Prepares a new PlotContentsDialog for creating a new plot using data from a ResultsTable. * Use showDialog thereafter. */ public PlotContentsDialog(String title, ResultsTable rt) { creatingPlot = true; dialogType = ADD_FROM_TABLE; if (rt == null || !isValid(rt)) { IJ.error("Cant Create Plot","No (results) table or no data in "+title); dialogType = ERROR; } plot = new Plot("Plot of "+title, "x", "y"); allTables = new ResultsTable[] {rt}; allTableNames = new String[] {title}; }
public void plot2d() { JGnuplot jg = new JGnuplot(); Plot plot = new Plot("") { { xlabel = "x"; ylabel = "y"; } }; double[] x = { 1, 2, 3, 4, 5 }, y1 = { 2, 4, 6, 8, 10 }, y2 = { 3, 6, 9, 12, 15 }; DataTableSet dts = plot.addNewDataTableSet("2D Plot"); dts.addNewDataTable("y=2x", x, y1); dts.addNewDataTable("y=3x", x, y2); jg.execute(plot, jg.plot2d); }
public void plot3d() { JGnuplot jg = new JGnuplot(); Plot plot = new Plot("") { { xlabel = "x"; ylabel = "y"; zlabel = "z"; } }; double[] x = { 1, 2, 3, 4, 5 }, y = { 2, 4, 6, 8, 10 }, z = { 3, 6, 9, 12, 15 }, z2 = { 2, 8, 18, 32, 50 }; DataTableSet dts = plot.addNewDataTableSet("3D Plot"); dts.addNewDataTable("z=x+y", x, y, z); dts.addNewDataTable("z=x*y", x, y, z2); jg.execute(plot, jg.plot3d); }
/** * Create plot with the precision-recall curve * @param stats classification statistics * @return precision-recall plot */ public static Plot createPrecisionRecallPlot( ArrayList< ClassificationStatistics > stats) { // Extract precision and recall values float[] precision = new float[ stats.size() ]; float[] recall = new float[ stats.size() ]; for(int i = 0; i < precision.length; i++) { precision[i] = (float) stats.get(i).precision; recall[i] = (float) stats.get(i).recall; } Plot pl = new Plot("Precision-Recall curve", "Recall [tp / (tp + fn)]", "Precision [tp / (tp+fp)]", recall, precision); pl.setLimits(0, 1, 0, 1); pl.setSize(540, 512); pl.setColor(Color.GREEN); return pl; }
/** * Plot the Receiver operating characteristic curve * @param stats classification statistics */ public static void plotROC( ArrayList< ClassificationStatistics > stats) { // Extract true positive and true negative rates float[] tpr = new float[ stats.size() ]; float[] fpr = new float[ stats.size() ]; for(int i = 0; i < tpr.length; i++) { tpr[i] = (float) stats.get(i).recall; fpr[i] = (float) (1f - stats.get(i).specificity); } Plot pl = new Plot("Receiver Operating Characteristic curve", "False Positive Rate (1 - specificity)", "True Positive Rate or sensitivity", fpr, tpr ); pl.setLimits(0, 1, 0, 1); pl.setSize(540, 512); pl.setColor(Color.RED); pl.show(); }
/** * Plot the precision-recall curve * @param stats classification statistics */ public static void plotPrecisionRecall( ArrayList< ClassificationStatistics > stats) { // Extract precision and recall values float[] precision = new float[ stats.size() ]; float[] recall = new float[ stats.size() ]; for(int i = 0; i < precision.length; i++) { precision[i] = (float) stats.get(i).precision; recall[i] = (float) stats.get(i).recall; } Plot pl = new Plot("Precision-Recall curve", "Recall [tp / (tp + fn)]", "Precision [tp / (tp+fp)]", recall, precision); pl.setLimits(0, 1, 0, 1); pl.setSize(540, 512); pl.setColor(Color.GREEN); pl.show(); }
/** Returns an ImageProcessor for the specified slice, were 1<=n<=nslices. Returns null if the stack is empty. */ public ImageProcessor getProcessor(int n) { byte[] bytes = (byte[])plots.get(n-1); if (bytes!=null) { try { Plot plot = new Plot(null, new ByteArrayInputStream(bytes)); ImageProcessor ip = plot.getProcessor(); if (bitDepth==24) ip = ip.convertToRGB(); else if (bitDepth==8) ip = ip.convertToByte(false); return ip; } catch (Exception e) { IJ.handleException(e); } } return null; }
/** Returns an ImageProcessor for the specified slice, were 1<=n<=nslices. Returns null if the stack is empty. */ public ImageProcessor getProcessor(int n) { byte[] bytes = (byte[])plots.get(n-1); if (bytes!=null) { try { Plot plot = new Plot(null, new ByteArrayInputStream(bytes)); ImageProcessor ip = plot.getProcessor(); if (bitDepth==24) ip = ip.convertToRGB(); else if (bitDepth==8) ip = ip.convertToByte(false); return ip; } catch (Exception e) { IJ.handleException(e); } } return null; }
public Plot getPlot() { if (profile==null) return null; String xLabel = "Distance ("+units+")"; int n = profile.length; if (xValues==null) { xValues = new float[n]; for (int i=0; i<n; i++) xValues[i] = (float)(i*xInc); } float[] yValues = new float[n]; for (int i=0; i<n; i++) yValues[i] = (float)profile[i]; boolean fixedYScale = fixedMin!=0.0 || fixedMax!=0.0; Plot plot = new Plot("Plot of "+getShortTitle(imp), xLabel, yLabel, xValues, yValues); if (fixedYScale) { double[] a = Tools.getMinMax(xValues); plot.setLimits(a[0],a[1],fixedMin,fixedMax); } return plot; }
public Plot getPlot() { if (profile==null) return null; String xLabel = "Distance ("+units+")"; int n = profile.length; if (xValues==null) { xValues = new float[n]; for (int i=0; i<n; i++) xValues[i] = (float)(i*xInc); } float[] yValues = new float[n]; for (int i=0; i<n; i++) yValues[i] = (float)profile[i]; boolean fixedYScale = fixedMin!=0.0 || fixedMax!=0.0; Plot plot = new Plot("Plot of "+getShortTitle(imp), xLabel, yLabel, xValues, yValues); if (fixedYScale) { double[] a = Tools.getMinMax(xValues); plot.setLimits(a[0],a[1],fixedMin,fixedMax); } return plot; }
public Plot getPlot() { double[] x = PlotUtils.range(0, series.length - 1); Plot plot = new Plot("Profile", "x", "intensity", x, series); PlotUtils.setLimits(plot, x, series, getX(), getIntensities()); plot.draw(); plot.setColor(Color.BLUE); plot.addPoints(getX(), getIntensities(), Plot.CIRCLE); return plot; } }
/** Plots a histogram of this image using the specified number of bins and returns the PlotWindow. */ public PlotWindow plotHistogram(int bins) { ImageStatistics stats = getStatistics(AREA+MEAN+MODE+MIN_MAX, bins); Plot plot = new Plot("Hist_"+getTitle(), "Value", "Frequency"); plot.setColor("black", "#999999"); plot.setFont(new Font("SansSerif",Font.PLAIN,14)); double[] y = stats.histogram(); int n = y.length; double[] x = new double[n]; int bits = getBitDepth(); boolean eightBit = bits==8 || bits==24; double min = !eightBit?stats.min:0; for (int i=0; i<n; i++) x[i] = min+i*stats.binSize; plot.add("bar", x, y); if (bins!=256) plot.addLegend(bins+" bins", "auto"); if (eightBit) plot.setLimits(0,256,0,Double.NaN); return plot.show(); }
double newPlot() { String title = getFirstString(); String xLabel = getNextString(); String yLabel = getNextString(); double[] x, y; if (interp.nextToken()==')') x = y = null; else { x = getNextArray(); if (interp.nextToken()==')') { y = x; x = new double[y.length]; for (int i=0; i<y.length; i++) x[i] = i; } else y = getNextArray(); } interp.getRightParen(); plot = new Plot(title, xLabel, yLabel, x, y); return Double.NaN; }
static public Plot makePlot(final CATAParameters cp, final String name, final VectorString3D c) { final double[] stdDev = c.getStdDevAtEachPoint(); if (null == stdDev) return null; final double[] index = new double[stdDev.length]; for (int i=0; i<index.length; i++) index[i] = i; Utils.log2("name is " + name); Utils.log2("c is " + c); Utils.log2("cp is " + cp); Utils.log2("stdDev is " + stdDev); Utils.log2("c.getCalibrationCopy() is " + c.getCalibrationCopy()); Utils.log2("c.getDelta() is " + c.getDelta()); final Calibration cal = c.getCalibrationCopy(); if (null == cal) Utils.log2("WARNING null calibration!"); final Plot plot = new Plot(name, name + " -- Point index (delta: " + Utils.cutNumber(c.getDelta(), 2) + " " + (null == cal ? "pixels" : cal.getUnits()) + ")", "Std Dev", index, stdDev); plot.setLimits(0, cp.plot_max_x, 0, cp.plot_max_y); plot.setSize(cp.plot_width, cp.plot_height); plot.setLineWidth(2); return plot; }