Tiled Graphs

This is used to plot a bunch of waves, or columns of waves, on one graph, each with its own set of axes. So you could plot 12 waves in a 4x3 matrix of "subgraphs". They are all still associated with the same window, though. Create a blank graph before using.

Function TileAppend(waves,rows,cols[,left,right,low,high,xLog,yLog,box,labels,xLabel,yLabel,xMargin,yMargin,grout])
    wave /wave waves // Can be a bunch of 1D waves, a matrix (will plot columns), or a stack (will plot beams, and use the dimension sizes of the stack instead of provided rows and cols values).  
    variable rows,cols
    variable left,right // Left and right values for x-axes.
    variable low,high // Low and high values for y-axes.
    variable xLog,yLog // Set x and/or y axes to log scale.  
    variable box // 0 for no mirror axes, 1 for only mirror x-axes, 2 for only mirror y-axes, and 3 for mirror axes both ways.  
    string labels // Labels for axes.  
    string xLabel,yLabel // Master labels for the axes.  
    variable xMargin,yMargin // Margins (as a fraction of graph size) for the axes closests to the edge of the graph window.  
    variable grout // Grout as a fraction of the graph window size.  
   
    xMargin=paramisdefault(xMargin) ? 0.02 : xMargin
    yMargin=paramisdefault(yMargin) ? 0.02 : yMargin
    grout=paramisdefault(grout) ? 0.02 : grout
   
    wave w=waves[0]
    if(dimsize(w,1)<=1) // One of a bunch of 1D waves.  
        variable numWaves=numpnts(waves)
        string mode="waves"
    elseif(dimsize(w,2)<=1) // A matrix.  
        numWaves=dimsize(w,1)
        mode="matrix"
    else // A stack.  
        numWaves=dimsize(w,0)*dimsize(w,1)
        rows=dimsize(w,0)
        cols=dimsize(w,1)
        mode="stack"
    endif
   
    variable i
    for(i=0;i<numwaves;i+=1)
        wave w=waves[i]
        if(!waveexists(w))
            continue
        endif      
        variable row=mod(i,rows)
        variable col=floor(i/rows)
        string yAxis,xAxis
        sprintf xAxis,"x_%d",col
        sprintf yAxis,"y_%d",row
        strswitch(mode)
            case "matrix":
                appendtograph /L=$yaxis /B=$xAxis w[][i]
                break
            case "stack":
                appendtograph /L=$yaxis /B=$xAxis w[row][col][]
                break
            default:
                appendtograph /L=$yaxis /B=$xAxis w
                break
        endswitch
       
        if(!paramisdefault(left) && !paramisdefault(right))
            setAxis $xAxis left,right
        endif
        if(!paramisdefault(low) && !paramisdefault(high))
            setAxis $yAxis low,high
        endif
        ModifyGraph axOffset($yAxis)=-4,axOffset($xAxis)=-1,btLen=1
        variable xLow=xMargin+col/cols*(1-xMargin)
        variable xHigh=xMargin+((col+1)/cols-grout)*(1-xMargin)
        variable yLow=yMargin+row/rows*(1-yMargin)//1-(row+1)/rows+yMargin
        variable yHigh=yMargin+((row+1)/rows-grout)*(1-yMargin)//1-row/rows-grout
        variable numXTicks=ceil(10/cols)
        variable numYTicks=ceil(10/rows)
        //print xLow,xHigh,yLow,yHigh
        modifygraph axisEnab($xAxis)={xLow,xHigh},freepos($xAxis)={yMargin,kwFraction},lblpos($xAxis)=100,nticks($xAxis)=numXTicks,log($xAxis)=xLog
        modifygraph axisEnab($yAxis)={yLow,yHigh},freepos($yAxis)={xMargin,kwFraction},lblpos($yAxis)=100,nticks($yAxis)=numYTicks,log($yAxis)=yLog
        if(!paramisdefault(labels))
            strswitch(labels)
                case "waveNames":
                    label $xAxis nameofwave(waves[col])
                    label $yAxis nameofwave(waves[row])
                    break
                case "dfNames":
                    label $xAxis getwavesdatafolder(waves[col],0)
                    label $yAxis getwavesdatafolder(waves[row],0)
                    break
                default:
                    label $xAxis stringfromlist(col,labels)
                    label $yAxis stringfromlist(row,labels)
                    break
            endswitch
        endif
        if(box & 1)
            if(row>0)
                sprintf xAxis,"xLow_%d_%d",row,col
                newfreeaxis /b $xAxis
                ModifyGraph axisEnab($xAxis)={xLow,xHigh},freepos($xAxis)={yLow,kwFraction},nticks($xAxis)=0
            endif
            sprintf xAxis,"xHigh_%d_%d",row,col
            newfreeaxis /b $xAxis
            ModifyGraph axisEnab($xAxis)={xLow,xHigh},freepos($xAxis)={yHigh,kwFraction},nticks($xAxis)=0
        endif
        if(box & 2)
            if(col>0)
                sprintf yAxis,"yLow_%d_%d",row,col
                newfreeaxis /l $yAxis
                ModifyGraph axisEnab($yAxis)={yLow,yHigh},freepos($yAxis)={xLow,kwFraction},nticks($yAxis)=0
            endif
            sprintf yAxis,"yHigh_%d_%d",row,col
            newfreeaxis /l $yAxis
            ModifyGraph axisEnab($yAxis)={yLow,yHigh},freepos($yAxis)={xHigh,kwFraction},nticks($yAxis)=0
        endif
    endfor
    if(!paramisdefault(xLabel))
        textbox /o=0/f=0/t=1/a=mt/x=0/y=0 xLabel
    endif
    if(!paramisdefault(yLabel))
        textbox /o=90/f=0/t=1/a=rc/x=0/y=0 yLabel
    endif
End

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More