/* Macros that create bar charts: ------------------------- Vertical Bars [1] Horizontal Bars [2] Monochrome Bars [3] N.Vischer, 03.02.18 2:04 */ close("*", "keep"); close("*.ijm", "keep"); horizontalBars(); monochromeBars(); verticalBars(); exit; macro "Vertical Bars [1]"{ verticalBars(); } macro "Horizontal Bars [2]"{ horizontalBars(); } macro "Monochrome Bars [3]"{ monochromeBars(); } function verticalBars() { Plot.create("Vertical Bars Demo", "{Apples\n(bio),Oranges,Cherries,Pears}", "Y"); yValues = newArray(7, 3, 5, 6); nBoxes = yValues.length; colors = split("red orange magenta green"); Plot.setFrameSize(700, 400); Plot.setLimits(-0.5, nBoxes-0.5, 0, 8); Plot.setFontSize(18); for (box = 0; box < nBoxes; box++){ Plot.setColor(colors[box], colors[box]); width = 0.2; left = box - width; right = box + width; Plot.drawShapes("rectangles", left, 0, right, yValues[box]); } Plot.show; } function horizontalBars() { Plot.create("Horizontal Bars Demo", "X", "{Apples\n(bio),Oranges,Cherries,Pears}"); Plot.setLimits(-0.5, 8, 0, 5); xx = newArray(7, 3, 5, 6); colors = split("red orange magenta green"); nBoxes = xx.length; Plot.setFrameSize(700, 400); Plot.setLimits(0, 10, -0.5, nBoxes); Plot.setFontSize(16); for (box = 0; box < nBoxes; box++){ Plot.setColor(colors[box], colors[box]); width = 0.25; bottom = box - width; top = box + width; Plot.drawShapes("rectangles", 0, bottom, xx[box], top); } Plot.show; } function monochromeBars() { Plot.create("Monochrome Bars Demo", "{Apples,Oranges,Cherries,Pears}", "Y"); yValues = newArray(7, 3, 5, 6); Plot.setFrameSize(700, 400); Plot.setLimits(-0.5, yValues.length-0.5, 0, 8); Plot.setFontSize(18); Plot.setLineWidth(2); Plot.setColor("blue", "#bbbbff"); Plot.add("bars", yValues); Plot.show; }