/* Plot_Results.bsh * IJ BAR: https://github.com/tferr/Scripts#scripts * Creates an ImageJ XY plot from imported spreadsheet data. TF, 2014.06 */ import ij.IJ; import ij.gui.GenericDialog; import ij.gui.Plot; import ij.io.Opener; import ij.plugin.Colors; import ij.util.Tools; import ij.measure.ResultsTable; // flags for axis design int[] flags = new int[12]; String[] labels = new String[12]; boolean[] choices = new boolean[12]; flags[0] = Plot.X_LOG_NUMBERS; choices[0] = false; labels[0] = "Logarithmic_scale_X"; flags[1] = Plot.Y_LOG_NUMBERS; choices[1] = false; labels[1] = "Logarithmic_scale_Y"; flags[2] = Plot.X_GRID; choices[2] = true; labels[2] = "Gridlines_X"; flags[3] = Plot.Y_GRID; choices[3] = true; labels[3] = "Gridlines_Y"; flags[4] = Plot.X_FORCE2GRID; choices[4] = false; labels[4] = "Grid_expands_axis_X"; flags[5] = Plot.Y_FORCE2GRID; choices[5] = false; labels[5] = "Grid_expands_axis_Y"; flags[6] = Plot.X_NUMBERS; choices[6] = true; labels[6] = "Labels_at_intervals_X"; flags[7] = Plot.Y_NUMBERS; choices[7] = true; labels[7] = "Labels_at_intervals_Y"; flags[8] = Plot.X_TICKS; choices[8] = true; labels[8] = "Major_ticks_X"; flags[9] = Plot.Y_TICKS; choices[9] = true; labels[9] = "Major_ticks_Y"; flags[10]= Plot.X_MINOR_TICKS; choices[10]= false; labels[10]= "Minor_ticks_X"; flags[11]= Plot.Y_MINOR_TICKS; choices[11]= false; labels[11]= "Minor_ticks_Y"; // flags for dataset design int[] shapes = new int[6]; String[] slabels = new String[6]; String[] colors = new String[6]; shapes[0] = Plot.LINE; slabels[0] = "Line"; colors[0] = "Black"; shapes[1] = Plot.BOX; slabels[1] = "Square"; colors[1] = "Gray"; shapes[2] = Plot.CIRCLE; slabels[2] = "Circle"; colors[2] = "Red"; shapes[3] = Plot.CROSS; slabels[3] = "Cross"; colors[3] = "Green"; shapes[4] = Plot.DOT; slabels[4] = "Dot"; colors[4] = "Blue"; shapes[5] = Plot.X; slabels[5] = "X"; colors[5] = "Magenta"; ResultsTable rt = ResultsTable.getResultsTable(); if (rt==null || rt.getCounter()==0) Opener.openResultsTable(""); rt = ResultsTable.getResultsTable(); if (rt==null || rt.getCounter()==0) { IJ.error("Could not retrieve data from Results table"); return; } String title = "Imported Data"; String[] headings = rt.getHeadings(); int nCols = headings.length; boolean noXvalues = (nCols>1) ? false : true; int xCol = 0; int yCol = (nCols>1) ? 1 : 0; int cColor = 1; int cShape = 3; boolean addSeries = true; GenericDialog gd = new GenericDialog("Plot Data"); gd.addStringField("Plot title:", title, 24); gd.addChoice("X-values:", headings, headings[xCol]); gd.setInsets(-5,20,10); gd.addCheckbox("Ignore X-values (use incremental counter)", noXvalues); gd.addChoice("Y-values:", headings, headings[yCol]); gd.setInsets(12,0,0); gd.addChoice("Style:", slabels, slabels[cShape]); gd.addChoice("Color:", colors, colors[cColor]); gd.addCheckboxGroup(flags.length/2, 2, labels, choices, new String[]{"X-axis:","Y-axis:"}); if (this.nCols>1) gd.enableYesNoCancel("Finish", "Add More Datasets"); gd.showDialog(); if (gd.wasCanceled()) return; else if (gd.wasOKed()) addSeries = false; title = gd.getNextString(); noXvalues = gd.getNextBoolean(); xCol = gd.getNextChoiceIndex(); yCol = gd.getNextChoiceIndex(); cShape = gd.getNextChoiceIndex(); cColor = gd.getNextChoiceIndex(); int cFlags = 0; for (int i=0; i