Mr. Hister takes a list of waves and plots them all evenly spaced with the same size and scaling. Good for comparing histograms.

Mr. Hister takes a string containing a semicolon-seprated list of waves (theHistList)and plots them all at the same size and scaling nicely arranged in a 2D matrix on single graph with multiple axes. Waves are plotted in the order they are listed, so you may want to sort the list appropriately first.

The layout and dimensions of the matrix of plots are determined by the parameters maxDownOrAcross and GoAcross. If GoAcross is 1, there are maxDownOrAcross plots in each row, and the rows are filled first, from left to right. If goAcross is 0, there are maxDownOrAcross plots in each column, and the columns are filled first, from top to bottom. In either case, the size of the dimension not specified by maxDownOrAcross is set by dividing the total number of waves by maxDownOrAcross.

Mr. Hister takes several optional parameters that control layout. The optional titleList is a semicolon-seprated list of strings to be used as tags to add a label to each plot. They must be in the same order as theHistList. If not specified, each plot is labeled with the name of the wave. To have no labels at all, specify titleList = ""

The font and font size for the titles can be set with optional parameters font and fontSize. The defaults is Arial size 10, but this can easily be changed in the first few lines of code.

The spacing between plots is adjustable with the optional parameter spacerPercent. Spacing is measured as a percentage of total horizontal and vertical size. One or two is usually about right.

The axis offset for all axes can be set as a percentage of axis range (the same percentage is used for both horizontal and vertical axes) with the optional parameter axesOffset. This is provided as Mr. Hister creates a free axis for each row and column, and axis standoff does not apply to free axes. The default value is 0 for no offset. For a noticeable offset, try two to five depending on how large a graph size you want to optimize presentation for.

The optional parameter frame underlines each plot (if 1) or draws a box around each plot (if 2). A value of 0 leaves the plots unadorned, and this is the default.
#pragma rtGlobals=1     // Use modern global access method.
#pragma IgorVersion=5
#pragma version = 1      // Last Modified: Jun 13 2008 by Jamie Boyd

Function MrHister (theHistList, maxDownOrAcross, GoAcross, [graphTitleStr, titleList, font, fontSize, spacerPercent, axesOffset, frame])
    string theHistList // list of  waves to be plotted
    variable maxDownOrAcross // number of histograms to appear in whichever of columns or rows is filled first.
        //Size of other dimension is determined by total number of graphs
    variable GoAcross // is 1 if  rows are filled first instead of columns
    string graphTitleStr // desired title for the graph
    string titleList // optional list of titles for each histogram, if not given, name of each wave is used for title
    string font // font for the titles, default is Arial
    variable fontSize // font size for the  titles, default is 10
    variable spacerPercent //Percent of total graph width/height that is used as space beteeen axes. default is 1%
    variable axesOffset // offset of axes, in percent, of axis range, for both vertical and horizontal. default is 0
    variable frame // 0 for no frame, 1 for underline, 2 for a box, default is no frame
    // Set default values for optional parameters
    if (ParamIsDefault(graphTitleStr))
        graphTitleStr = "Mr. Hister"
    variable UsedefaultTitles = 0
    if( ParamIsDefault(titleList))
        titleList = ""
        UsedefaultTitles = 1
    elseif (cmpStr (titleList, "") == 0)
        UsedefaultTitles =-1
    if( ParamIsDefault(fontSIze))
        fontSIze = 10
    string fontSizeStr = num2str (fontSize)
    if (fontSize < 10)
        fontSizeStr = "0" + fontSizeStr
    if( ParamIsDefault(font))
        font = "Arial"
    if (ParamisDefault (SpacerPercent))
        SpacerPercent = 1
    SpacerPercent *= .01 // to change from percent to proportion
    //Find maximum and minimum  X and Y values to make all graphs scaled the same
    // Use the same loop to set the default title to the wave name, if using default titles
    variable ii, numHists = itemsinList (theHistList)
    variable maxScal = 0,  maxSecs =0  
    variable minScal = INF, minSecs = INF
    FOR (ii =0 ; ii < numHists; ii+= 1)
        WAVE thehist = $stringfromlist (ii, theHistList, ";")
        if (UsedefaultTitles==1) // default title is the name of the wave.
            titleList += nameofwave (theHist) + ";"
        wavestats/q thehist
        maxScal = max(V_max, maxScal)
        minScal = min (V_min, minScal)
        maxSecs = max (maxSecs, rightx (thehist))
        minSecs = min (minSecs, leftx (thehist))
     //Decommentize next line to add a multiplier to ensure a little room on top of each graph for the label.
        //maxscal = maxScal + ((maxScal - MinScal)*0.05)
    //Figure out the proportion of total vertical and horizontal space for each graph and the number of
        //graphs in each row and column. The way this works is that the function is given  one of rows or
        //columns with maxDownOrAcross, and the size of the other dimeniosn  is calulated from the number of graphs.
    variable leftpercent, bottompercent
    if (GoAcross)
        if (numHists <= maxDownOrAcross)
            bottompercent = (1/ (numHists))
            bottompercent = (1/maxDownOrAcross)
        if (numHists > maxDownOrAcross)
            leftpercent = 1/(ceil(numHists/maxDownOrAcross))
            leftpercent= 1
        if (numHists <= maxDownOrAcross)
            leftpercent = (1/ (numHists))
            leftpercent = (1/maxDownOrAcross)
        if (numHists > maxDownOrAcross)
            bottompercent = 1/(ceil(numHists/maxDownOrAcross))
            bottompercent= 1
    // Each row and column gets its own vertical or horizontal axis
    string Laxis, Baxis, condtag
    display as graphTitleStr
    For (ii = 0; ii < numHists; ii += 1)
        WAVE thehist =$stringfromlist (ii, theHistList, ";")
        condtag =  "\\Z" + fontSizeStr + "\\F'" + font + "' " + stringfromlist (ii, titleList, ";")
        if (GoAcross)
            Laxis = "L_" + num2str (floor (ii/maxDownOrAcross))     //down the column varies slowly
            Baxis = "B_" +  num2str (mod (ii, maxDownOrAcross))     //across the row varies quickly
            Laxis = "L_" + num2str (mod (ii, maxDownOrAcross))      //down the column varies quickly
            Baxis = "B_" + num2str (floor (ii/maxDownOrAcross))     //across the row varies slowly
        appendtograph/L = $Laxis/B = $Baxis thehist
        SetAxis $Laxis  minScal, maxScal
        SetAxis $Baxis  minSecs, maxSecs
        if (GoAcross)
            ModifyGraph axisEnab($Laxis)={1 - ((leftpercent *(floor (ii/maxDownOrAcross)))+ leftpercent - (2*SpacerPercent)),(1-((leftpercent * (floor (ii/maxDownOrAcross))) + (2*SpacerPercent)))}
            ModifyGraph axisEnab($Baxis)={((bottompercent *  (mod (ii, maxDownOrAcross)))+ SpacerPercent),(((bottompercent * (mod (ii, maxDownOrAcross))) + bottompercent - SpacerPercent))}
            ModifyGraph axisEnab($Laxis)={1 - ((leftpercent * (mod (ii, maxDownOrAcross)))+ leftpercent - (2*SpacerPercent)),(1-((leftpercent * (mod (ii, maxDownOrAcross))) + (2*SpacerPercent)))}
            ModifyGraph axisEnab($Baxis)={((bottompercent * (floor (ii/maxDownOrAcross)))+ SpacerPercent),(((bottompercent * (floor (ii/maxDownOrAcross))) + bottompercent - SpacerPercent))}
        if (frame)
            SetDrawLayer UserBack
            SetDrawEnv xcoord= $Baxis,ycoord= $Laxis
            SetDrawEnv fillpat= 0
            if (frame == 1)
                DrawLine minSecs,minScal,maxSecs,minScal // each histogram underlined
            elseif (frame == 2)
                DrawRect minSecs,minScal, maxSecs, maxscal  // a neat little box around each histogram
        if (UsedefaultTitles > -1)
            Tag/N= $("text" + num2str (ii))/B=1/F=0/A=LT/L=0 $NameOfWave(thehist), minSecs, condtag
    //Modify axes crossings to give an axis standoff as percentage of axis range (standoff  do much for free axes)
    variable bOffset = minSecs - ((maxSecs - minSecs) * axesOffset * .01)
    variable lOffset = minScal - ((maxScal - minScal) * axesOffset * .01)
    // Iterate through list of axes, both left and bottom
    variable nLaxes,nBaxes
    if (GoAcross)
         nLaxes = floor (numHists/maxDownOrAcross) + 1
         nBaxes = maxDownOrAcross
        nLaxes = maxDownOrAcross
        nBaxes = floor (numHists/maxDownOrAcross) + 1
    string LastLaxis = "L_" + num2str (nLaxes -1)
    for (ii = 0; ii < nLaxes; ii += 1)
        Laxis = "L_" + num2str (ii)
        ModifyGraph freePos($Laxis)={bOffset,B_0}
    for(ii = 0; ii < nBaxes; ii += 1)
        Baxis = "B_" + num2str (ii)
        ModifyGraph freePos($Baxis)={lOffset,$LastLaxis}
    // set graph to Histogram mode. You can change this to whatever you like
    ModifyGraph mode=5,hbFill=2,rgb=(0,0,0)
    // Name the graph same as the graph title, but cleaned up
    string winNameStr = uniquename (cleanupName(graphTitleStr, 0), 6, 0)
    DoWindow/C  $winNameStr
Have you seen the Scatter Plot Matrix package? You will find it in Windows->New->Packages->Scatter Plot Matrix.

There is a demo experiment as well, File->Example Experiments->Graphing Techniques->Scatter Plot Matrix Demo.

John Weeks
WaveMetrics, Inc.




Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More