/* Distribution_Plotter.ijm * IJ BAR: https://github.com/tferr/Scripts#scripts * * Plots cumulative and relative frequencies from data in the Results table. A Gaussian * curve (normal distribution) is fitted to the histogram. Requires at least IJ 1.48q. * Distribution tables can be accessed through the 'List' button of the plot window: * X0: Bin start, Y0: Relative frequencies; X1: Values, Y1: Cumulative frequencies. * * TF, 2009.11 Initial version * TF, 2014.02 Methods for optimal number of bins, fit to Normal distribution * TF, 2014.12 Bug fix: Column headings containing spaces were not parsed properly */ plotSize = 300; // Size (in pixels) of histogram canvas histScale = 0.77; // Height of modal class relatively to axis of cumulative frequencies resCount = nResults; if (resCount==0 || !isOpen("Results")) exit("The Results table is empty."); tabChoices = newArray('Number of values', 'Relative frequency (%)', 'Relative frequency (fractions)'); binChoices = newArray("Square-root", "Sturges", "Scott (IJ's default)", "Freedman-Diaconis", "Specify manually below:"); Dialog.create('Distribution Plotter'); prmtrs = getParameters(); Dialog.addChoice("Parameter:", prmtrs); Dialog.addChoice('Tabulate:', tabChoices); Dialog.addRadioButtonGroup("Automatic binning:", binChoices, 3, 2, binChoices[3]); Dialog.addSlider("Bins:", 2, resCount, sqrt(resCount)); Dialog.addCheckbox("Ignore zeros", false); Dialog.addMessage(resCount +" data points (NB: 'NaN' values will be ignored)..."); Dialog.show; parameter = Dialog.getChoice; yAxis = Dialog.getChoice; autoBin = Dialog.getRadioButton; userBins = Dialog.getNumber; if (isNaN(userBins)) userBins = 2; userBins = maxOf(2, minOf(userBins, resCount)); ignoreZeros = Dialog.getCheckbox; for (i=0, countInvalid=0; ibinArray[nBins-1]) counts[nBins-1] += 1; else { for (j=1; j=binArray[j-1] && value