/** * 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(); }
Plot p = new Plot("FRC Of "+name, "Spatial Frequency", "Correlation"); p.setLineWidth(1); p.setLimits(0, x[x.length-1], 0, 1); p.setColor(new Color(0, 0, 0)); p.addPoints(x, y, PlotWindow.LINE); p.setColor(new Color(255, 120, 120)); p.addPoints(x, sy, PlotWindow.LINE); p.setColor(new Color(120, 120, 255)); p.addPoints(x, thr_curve, PlotWindow.LINE); p.setColor(new Color(69, 69, 69)); p.drawLine(1/fire, 0, 1/fire, 1); p.addLabel(0.02, 0.3, "FIRE = "+String.format("%.3f", fire)); p.addLegend("FRC\nSmoothed FRC\nThreshold");
/** Draws the plot (if not done before) in an ImageProcessor and returns the ImageProcessor with the plot. */ public ImageProcessor getProcessor() { draw(); return ip; }
/** Adds a set of points to the plot using double ArrayLists. * Must be called before the plot is displayed. */ public void addPoints(ArrayList x, ArrayList y, int shape) { addPoints(getDoubleFromArrayList(x), getDoubleFromArrayList(y), shape); }
/** Sets the plot frame size in (unscaled) pixels. This size does not include the * borders with the axis labels. Also sets the scale to 1.0. * This frame size in pixels divided by the data range defines the image scale. * This method does not check for the minimum size MIN_FRAMEWIDTH, MIN_FRAMEHEIGHT. * Note that the black frame will have an outer size that is one pixel larger * (when plotted with a linewidth of one pixel). */ public void setFrameSize(int width, int height) { if (pp.width <= 0) { //plot not drawn yet? Just remember as preferred size preferredPlotWidth = width; preferredPlotHeight = height; scale = 1.0f; } else { makeMarginValues(); width += leftMargin+rightMargin; height += topMargin+bottomMargin; setSize(width, height); } }
/** Obsolete, replaced by "new Plot(title,xLabel,yLabel,flags); add(shape,x,y);". * @deprecated */ public Plot(String title, String xLabel, String yLabel, float[] xValues, float[] yValues, int flags) { this.title = title; pp.axisFlags = flags; setXYLabels(xLabel, yLabel); if (yValues != null && yValues.length>0) { addPoints(xValues, yValues, /*yErrorBars=*/null, LINE, /*label=*/null); allPlotObjects.get(0).flags = PlotObject.CONSTRUCTOR_DATA; } }
driftY[i] = offset.y; Plot plot = new Plot("Drift", "frame", "drift [" + driftCorrection.getUnits() + "]", (float[]) null, null); if(driftCorrection.getDriftDataX().length > 50) { plot.setFrameSize(1280, 720); plot.setLimits(minFrame, driftCorrection.getMaxFrame(), Math.min(VectorMath.min(driftCorrection.getDriftDataX()), VectorMath.min(driftCorrection.getDriftDataY())), Math.max(VectorMath.max(driftCorrection.getDriftDataX()), VectorMath.max(driftCorrection.getDriftDataY()))); plot.setColor(new Color(255, 128, 128)); plot.addPoints(driftCorrection.getDriftDataFrame(), driftCorrection.getDriftDataX(), Plot.CROSS); plot.draw(); plot.setColor(new Color(128, 255, 128)); plot.addPoints(driftCorrection.getDriftDataFrame(), driftCorrection.getDriftDataY(), Plot.CROSS); plot.setColor(Color.red); plot.addPoints(grid, driftX, Plot.LINE); plot.addLabel(0.05, 0.8, "x drift"); plot.setColor(Color.green); plot.addPoints(grid, driftY, Plot.LINE); plot.addLabel(0.05, 0.9, "y drift"); plot.show();
/** 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(); }
title = imp.getTitle()+"-0-0"; Plot plot = new Plot(title, xAxisLabel, "Mean", x, y); if (x.length<=60) { plot.setColor(Color.red); plot.addPoints(x, y, Plot.CIRCLE); plot.setColor(Color.black); double[] a = Tools.getMinMax(x); double xmin=a[0]; double xmax=a[1]; plot.setLimits(xmin, xmax, ymin, ymax); plot.setLineWidth(2); plot.setColor(Color.blue); plot.drawNormalizedLine(xx, 0, xx, 1.0); plot.setColor(Color.black); plot.setLineWidth(1);
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; } }
Plot plot = new Plot("Sigma", "z [nm]", "sigma [px]", null, (float[]) null); plot.setSize(1024, 768); plot.setLimits(-2*zRange, +2*zRange, 0, stageStep); double[] xVals = new double[(int)(2*zRange/stageStep) * 2 + 1]; for(int val = -2*(int)zRange, i = 0; val <= +2*(int)zRange; val += stageStep, i++) { xVals[i] = val; plot.draw(); plot.show();
final Plot plot = new Plot("Profile t=" + t, "x" + ("".equals(pixelSpacingUnit) ? "" : (" (" + pixelSpacingUnit + ")")), "phase (× 2π)"); plot.setLimits(0, maxX, minPhase / pi2, maxPhase / pi2); plot.setFrameSize(850, 400); plot.addPoints(range(0, p[i].length, pixelSpacing), divide(p[i], pi2), Plot.LINE); plot.setColor(Color.BLUE); plot.setLineWidth(2); plot.addPoints(range(0, median[t].length, pixelSpacing), divide(median[t], pi2), Plot.LINE); final ImageProcessor ip = plot.getProcessor(); if (imageStack == null) imageStack = new ImageStack(ip.getWidth(), ip.getHeight()); imageStack.addSlice("t=" + t, ip);
/** For "Add from Table" and "Add from Arrays" adds item to the plot according to the current Choice settings * and sets the Style fields for it. */ private void addObjectFromTable() { float[][] data = getDataArrays(); if (data[1] == null) return; //no y data? then can't plot String label = columnChoice[1].getSelectedItem(); //take label from y int shape = Plot.toShape(symbolChoice.getSelectedItem()); float lineWidth = (float)(Tools.parseDouble(widthField.getText())); if (lineWidth > 0) plot.setLineWidth(lineWidth); plot.restorePlotObjects(); if (savedLimits != null) plot.setLimits(savedLimits); plot.setColor(colorField.getText(), color2Field.getText()); plot.addPoints(data[0], data[1], data[3], shape, label); if (data[2] != null) plot.addHorizontalErrorBars(data[2]); if (creatingPlot) { plot.setXYLabels(data[0]==null ? "x" : columnChoice[0].getSelectedItem(), columnChoice[1].getSelectedItem()); plot.setLimitsToFit(false); } else plot.fitRangeToLastPlotObject(); currentObjectIndex = plot.getNumPlotObjects()-1; setDialogStyleFields(currentObjectIndex); if (dialogType == ADD_FROM_TABLE) previousTableName = allTableNames[tableChoice.getSelectedIndex()]; }
new GenericDialog(HEADINGS[dialogType], parent); if (dialogType == SET_RANGE) { double[] currentMinMax = plot.getLimits(); boolean livePlot = plot.plotMaker != null; int xDigits = plot.logXAxis ? -2 : Plot.getDigits(currentMinMax[0], currentMinMax[1], 0.005*Math.abs(currentMinMax[1]-currentMinMax[0]), 6); int yDigits = plot.logYAxis ? -2 : Plot.getDigits(currentMinMax[2], currentMinMax[3], 0.005*Math.abs(currentMinMax[3]-currentMinMax[2]), 6); gd.addNumericField("X_From*", currentMinMax[0], xDigits); gd.addNumericField("X_To*", currentMinMax[1], xDigits); if (livePlot) gd.addCheckbox("Fix_X Range While Live", (plot.templateFlags & Plot.X_RANGE) != 0); gd.addCheckbox("Log_X Axis", (plot.hasFlag(Plot.X_LOG_NUMBERS))); gd.setInsets(20, 0, 3); //top, left, bottom gd.addNumericField("Y_From*", currentMinMax[2], yDigits); if (livePlot) gd.addCheckbox("Fix_Y Range While Live", (plot.templateFlags & Plot.Y_RANGE) != 0); gd.addCheckbox("Log_Y Axis", (plot.hasFlag(Plot.Y_LOG_NUMBERS))); gd.addMessage("*Leave empty for automatic range", new Font("SansSerif", Font.PLAIN, 12)); //n__ begin PlotDialog gd.showDialog(); if (gd.wasCanceled()) return; plot.saveMinMax(); double linXMin = gd.getNextNumber(); if (gd.invalidNumber()) if (livePlot) plot.templateFlags = setFlag(plot.templateFlags, Plot.Y_RANGE, gd.getNextBoolean()); boolean yLog = gd.getNextBoolean(); plot.setAxisXLog(xLog);
if (!creatingPlot) savedLimits = plot.getLimits(); plot.savePlotObjects(); String[] designations = plot.getPlotObjectDesignations(); if (dialogType == STYLE && designations.length==0) { IJ.error("Empty Plot"); if (parent == null && plot.getImagePlus() != null) parent = plot.getImagePlus().getWindow(); gd = parent == null ? new GenericDialog(HEADINGS[dialogType]) : new GenericDialog(HEADINGS[dialogType], parent); if (creatingPlot) tableChoice.setEnabled(false); // we can't select the table, we have only one } else if (dialogType == ADD_FIT) { String[] dataSources = plot.getDataObjectDesignations(); if (dataSources.length == 0) { IJ.error("No Data For Fitting"); else if (dialogType == ADD_FIT) addFitCurve(); plot.updateImage(); if (creatingPlot) { boolean recording = Recorder.record; Recorder.record = false; // don't record creating the image as image selection plot.show(); if (recording) Recorder.record = true; ImagePlus imp = plot.getImagePlus(); if (imp != null) imp.close(); } else {
interp.error("No plot window and no plot under construction"); if (name.equals("setFrameSize")) { currentPlot.setFrameSize((int)getFirstArg(), (int)getLastArg()); return Double.NaN; } else if (name.equals("setLimits")) { currentPlot.setLimits(getFirstArg(), getNextArg(), getNextArg(), getLastArg()); return Double.NaN; } else if (name.equals("setLimitsToFit")) { interp.getParens(); currentPlot.setLimitsToFit(true); return Double.NaN; } else if (name.equals("setLogScaleX")) { if (interp.nextNextToken()==')') { //no-argument call setLogScaleX() means true interp.getParens(); currentPlot.setAxisXLog(true); } else currentPlot.setAxisXLog(getBooleanArg()); currentPlot.updateImage(); return Double.NaN; } else if (name.equals("setLogScaleY")) { if (interp.nextNextToken()==')') { interp.getParens(); currentPlot.setAxisYLog(true); } else currentPlot.setAxisYLog(getBooleanArg()); currentPlot.updateImage(); return Double.NaN; } else if (name.equals("getLimits")) {
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; }
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; }
/** 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); }