Stacked plots / Multiple plots LAYOUT

REQUIRES IGOR PRO 7!

Similar to:
http://www.igorexchange.com/node/7210

but displays existing graphs in a single layout page. Note, that the layout is set to a custom size to preserve the original, absolute graph sizes. The entire layout may then be saved as a single graph. Execute the following to try it:

make/D/O/N=1000 aa, bb, cc, dd
setscale/i x, 0, 3*pi, "", aa,bb, cc, dd
aa=sin(x); display aa
bb=cos(x); display bb
cc=tan(x); display cc
dd=abs(sin(x)); display dd


Then use the snippet...

function MultiGraphLayout(GraphList, nCols, spacing, layoutName)
    string GraphList        // semicolon separated list of graphs to be appended to layout
    variable nCols      // number of graph columns
    string layoutName   // name of the layout
    variable spacing        // spacing between graphs in points!
   
    // how many graphs are there and how many rows are required
    variable nGraphs = ItemsInList(GraphList)
    variable nRows = ceil(nGraphs / nCols)
    variable LayoutWidth, LayoutHeight 
    variable gWidth, gHeight
    variable maxWidth = 0, maxHeight = 0
    variable left, top
    variable i, j, n = 0

    string ThisGraph

    // detect total layout size from individual graph sizes; get maximum graph size as column/row size
    for(i=0; i<nGraphs; i+=1)
       
        ThisGraph = StringFromList(i, GraphList)
        GetWindow $ThisGraph gsize
        gWidth = (V_right - V_left)
        gHeight = (V_bottom - V_top)
       
        // update maximum
        maxWidth = gWidth > maxWidth ? gWidth : maxWidth
        maxHeight = gHeight > maxHeight ? gHeight : maxHeight  
    endfor
   
    // calculate layout size
    LayoutWidth = maxWidth * nCols + ((nCols + 1) * spacing)
    LayoutHeight = maxHeight * nRows + ((nRows +1) * spacing)
   
    // make layout; kill if it exists
    DoWindow $layoutName
    if(V_flag)
        KillWindow $layoutName
    endif
   
    NewLayout/N=$layoutName/K=1/W=(517,55,1451,800)
    LayoutPageAction size=(LayoutWidth, LayoutHeight), margins=(0,0,0,0)
    ModifyLayout mag=0.75
   
    //append graphs
    top = spacing
    for(i=0; i<nRows; i+=1)
   
        // reset vertical position for each column
        left = spacing
       
        for (j=0; j<    nCols; j+=1)
       
            ThisGraph = StringFromList(n, GraphList)
            if(strlen(ThisGraph) == 0)
                return 0
            endif
           
            GetWindow $ThisGraph gsize
            gWidth = (V_right - V_left)
            gHeight = (V_bottom - V_top)
           
            AppendLayoutObject/F=0 /D=1 /R=(left, top, (left + gWidth), (top + gHeight)) graph $ThisGraph
       
            // shift next starting positions to the right
            left += maxWidth + spacing
           
            // increase plot counter
            n += 1             
        endfor  
       
        // shift next starting positions dwon
        top += maxHeight + spacing
    endfor
   
    return 1
end


...and append all graphs into one layout with:

MultiGraphLayout(WinList("*", ";", "WIN:1"), 2, 20, "AllGraphLayout")



Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More