// This macro demonstrates some new features of plots in ImageJ 1.49t // Michael Schmid 2015-05-03 var allTexts = ""; macro "Some New Plot Features" { requires("1.49t"); saveSettings(); run("Profile Plot Options...", "width=500 height=400 font=12 minimum=0 maximum=0 draw interpolate sub-pixel"); slowness = 1.5; //change for faster (<1) or slower (>1) animation if (slowness > 3) slowness = 3; // Create data n = 1001; x = newArray(n); y = newArray(n); value = 0; for (i=0; iZoom>View 100% or\nMore>>Reset Format\nto get the size defined in\nEdit>Options>Profile Plot Options"); wait(3200*slowness); run("View 100%"); wait(1500*slowness); Plot.setFrameSize(500, 400); showText("Image>Zoom>In or\nthe '+' key zooms in (both, x&y)"); wait(2800*slowness); run("In [+]"); wait(1000*slowness); showText("Image>Zoom>Out or\nthe '-' key zooms out"); wait(2800*slowness); run("Out [-]"); wait(1000*slowness); showText("Put the cursor below the x axis to zoom in/out\nhorizontally"); wait(1500*slowness); makeArrow(327, 450, 306, 426, "filled"); Roi.setStrokeWidth(2); Roi.setStrokeColor("black"); wait(1000*slowness); Roi.move(2000,2000); wait(500*slowness); Roi.move(306, 426); wait(2000*slowness); Plot.setLimits(220, 720, 0, 4); wait(1000*slowness); showText("Put the cursor left of the y axis to zoom in/out\nvertically"); wait(1000*slowness); makeArrow(27, 330, 6, 306, "filled"); Roi.setStrokeWidth(2); Roi.setStrokeColor("black"); wait(500*slowness); Roi.move(2000,2000); wait(500*slowness); Roi.move(6, 306); wait(1500*slowness); Plot.setLimits(220, 720, 0.1, 2.1); wait(1000*slowness); showText("With the cursor below or left of the plot,\narrows appear"); wait(1000*slowness); Plot.getLimits(xmin, xmax, ymin, ymax); toUnscaled(xmin, ymin); toUnscaled(xmax, ymax); x = 3; b=6; makePolygon(x-0.6, ymin-2.9, x+b, ymin-3.6-b, x+b+b+0.6, ymin-2.9); Overlay.addSelection("", 0, "#808080"); makePolygon(x, ymin +3, x+b, ymin +3+b-0.1, x+b+b+0.1, ymin+3); Overlay.addSelection("", 0, "#808080"); makePolygon(x, ymax +3, x+b, ymax +3+b-0.1, x+b+b+0.1, ymax +3); Overlay.addSelection("", 0, "#808080"); makePolygon(x-0.6, ymax-2.9, x+b, ymax-3.6-b, x+b+b+0.6, ymax-2.9); Overlay.addSelection("", 0, "#808080"); run("Select None"); wait(2000*slowness); showText("Click on an arrow to shift the limit"); makePolygon(x-0.6, ymin-2.9, x+b, ymin-3.6-b, x+b+b+0.6, ymin-2.9); Overlay.addSelection("", 0, "#808080"); makePolygon(x, ymin +3, x+b, ymin +3+b-0.1, x+b+b+0.1, ymin+3); Overlay.addSelection("", 0, "#808080"); makePolygon(x, ymax +3, x+b, ymax +3+b-0.1, x+b+b+0.1, ymax +3); Overlay.addSelection("", 0, "#808080"); makePolygon(x-0.6, ymax-2.9, x+b, ymax-3.6-b, x+b+b+0.6, ymax-2.9); Overlay.addSelection("", 0, "#ff0000"); run("Select None"); wait(2000*slowness); Plot.getLimits(xmin, xmax, ymin, ymax); ymaxNew = ymin +1.41*(ymax-ymin); Plot.setLimits(xmin, xmax, ymin, ymaxNew); wait(1000*slowness); Plot.setLimits(0, 1000, 0, 5); wait(1000*slowness); showText("With a selection, the '+' key,\nImage>Zoom>In, and Zoom to Selection\nset the data range to the selection"); for (i=0; i<3; i++) { run("Select None"); wait(500*slowness); makeRectangle(103,270,52,80); run("Properties... ", " stroke=red width=2"); wait(500*slowness); } wait(1000*slowness); run("In [+]"); wait(1000*slowness); showText("Image>Zoom>Original Scale\nreverts to the original data range"); wait(2000*slowness); Plot.setLimits(0, 1000, 0, 5); wait(1000*slowness); showText("Image>Zoom>Scale to Fit\nsets the scale to fit all data"); wait(2000*slowness); run("Scale to Fit"); //Plot.setLimitsToFit; //equivalent wait(2000*slowness); Plot.setLimits(100, 200, 0, 5); showText("Pan (hand tool) to shift the display range"); makePolygon(140,170,136,163,136,161,137,160,141,164,142,153,143,152,144,153,144,161,145,159,146,159,147,161,148,159,149,159,150,161,150,166,147,170); Overlay.addSelection("black"); run("Select None"); wait(2000*slowness); getPixelSize(unit, pixelWidth, pixelHeight); for (i=0; i<28; i++) { Plot.setLimits(100-3*i, 200-3*i, 0, 5); Overlay.moveSelection(1, 136+3*i/pixelWidth, 150); wait(30*slowness); } wait(1500*slowness); showText("Select whether axes should have ticks, grids etc.\nin More>> Axis Options"); wait(500*slowness); Plot.setFormatFlags("11000000000000"); wait(1500*slowness); Plot.setFormatFlags("11000000001111"); wait(1500*slowness); Plot.setFormatFlags("11001100001111"); wait(1500*slowness); Plot.setFormatFlags("11001100111111"); wait(1500*slowness); Plot.setFormatFlags("110000"); wait(1500*slowness); Plot.setFormatFlags("11001100001111"); wait(1500*slowness); showText("Adjust the font size in More>> Axis Options\nor in Profile Plot Options (for future plots)"); wait(500*slowness); for (i=9; i<=16; i++) { Plot.setFontSize(i); wait(500*slowness); } Plot.setFontSize(16); wait(2000*slowness); showText("\n\n\nPlots can now have a legend"); wait(500*slowness); Plot.setColor("black"); //Plot.addLegend("This is a line\nMaxima\nMinima"); Plot.setLegend("This is a line\nMaxima\nMinima"); wait(1500*slowness); showText("\n\n\nWith auto legend position, the legend tries\nto not obscure the data"); wait(2000*slowness); Plot.setLimits(200, 500, 0, 3); wait(1500*slowness); Plot.setLimits(200, 500, -3, 2.2); wait(1500*slowness); Plot.setLimits(0, 1000, 0, 4); wait(1500*slowness); wait(2500*slowness); showText("\n\nFinally, you can have a high-resolution\n(publication-quality) version of your plot:\nMore>>High-Resolution Plot"); wait(3000*slowness); Overlay.clear; Overlay.show; Plot.makeHighResolution("Demonstration plot with high resolution",3.0); print(allTexts); restoreSettings(); } function showText(text) { Overlay.clear; Overlay.show; wait(700*slowness); Overlay.drawString(text, 85, 50); Overlay.show; if (lengthOf(text)>1) allTexts = allTexts + replace(replace(text, "^\n*", ""),"\n"," ")+"\n"; }