Density Plot

I'm trying to do something pretty simple - take a stack of superimposed 1D waves and make a density plot showing the relative density of points. I've done some searching; am I missing a built-in way to do this in Igor or could someone give me a suggestion? I basically want the program to look at the superimposition of waves, figure out how many points are in a given box size and normalize the results. Thanks and let me know if I should provide more information. Much appreciated.
I've done something pretty similar, using a histogramming technique.

Decide how many bins you want on the x and y axes. Then go through each of your waves and decide how much 'frequency' you want to add to each bin in the density plot. You probably then need to decide how to normalise the probability along each axis.

A.
n213 wrote:
I'm trying to do something pretty simple - take a stack of superimposed 1D waves and make a density plot showing the relative density of points. I've done some searching; am I missing a built-in way to do this in Igor or could someone give me a suggestion?


I'm not sure what you mean by superimposed 1D waves, but basically what you are asking is a histogram. Igor's built-in histogram operation supports accumulating histograms from the input wave with the previous content of the histogram, using the /A flag. So, for example, if you wanted 60 boxes between -3 and +3, and your superimposed waves were called superimposed1DWave_1 through superimposed1DWave_5, something like this would do the trick:

Make/N=60 W_histogram=0
SetScale/P x -3, 0.05, "" W_histogram
Variable index
String S_waveName
for (index=1; index<=5; index+=1)
   S_waveName = "superimposed1DWave_"+num2istr(index)
   Histogram/A $S_waveName, W_histogram
endfor
Display W_histogram
ModifyGraph mode=5


Note that you need a lot of data points to get a nice-looking histogram, and the histogram discards a lot of detail from the data. So whereas it is certainly useful when you have a lot of poor-quality data points to reduce that information to a histogram, if you have a small number of high-quality measurements there are probably better ways to process the data. In particular, there is a one-to-one correspondence between the cumulative histogram and sorting the data points (you plot the sorted data values on the x axis and (0.5+p)/numpnts on the y axis), except that the cumulative histogram involves an extra step of rounding all the data values to the bin centers. So for calculations with histograms it is often better to express everything in terms of the cumulative histogram, and use the sorted data values as your best guess at what the cumulative histogram looks like.
In general a density plot requires a 2D histogram. Add this:
#include <Bivariate Histogram 2>

Near the top of your Procedure window (select Windows->Procedure Windows->Procedure Window) and close the window. Now you have Bivariate Histogram in your Macros menu. To learn how to use it, see documentation in comments at the top of the code. Select Windows->Procedure Windows->Bivariate Histogram 2.ipf.

If your data are in a bunch of 1D waves, you will need to concatenate them into a single 1D XY pair. You can use the Concatenate operation to do that:
Concatenate/NP {wave1, wave2, ...} destWave

If your waves have some systematic naming convention, you can use WaveList to generate the list of waves needed for this. For instance, if the waves follow the naming convention wave, you might do this:
Concatenate/NP WaveList("wave*", ";", ""), destWave

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
[quote=n213]Thanks all for the suggestions, but that is not exactly what I want to do. Here's a link to an image that shows on the left what my data looks like and on the right, the sort of density plot I'm trying to get.

http://ars.els-cdn.com/content/image/1-s2.0-S0969212605000195-gr2.jpg[/…]

I think John already gave the answer. You'll need the Bivariate Histogram package. Concatenate your force and distance waves using the /NP flag and run the Bivariate Histogram functions from the macros menu. That will give you a 2D wave which is equivalent to the figure you showed. I don't know if that works with scaled waves in case you only have one 1D data waves where the distance is set using SetScale. But you could duplicate the data wave and use something like xWave = x to have a separate x wave for that purpose.

EDIT:

try this and copy the following in the procedure window:

#include <Bivariate Histogram 2>

function MakeData()
    variable i 
    NewDataFolder/O/S tmp
   
    for (i=0; i<100; i+=1)
   
        Make/D/O/N=50 $"YY"+num2str(i)  //make fake data wave
        wave w= $"YY"+num2str(i)
       
        Make/D/O/N=50 $"XX"+num2str(i)  // make x data
        wave xw= $"XX"+num2str(i)
        xw = x
       
        w= gauss(x, (25+enoise(5)), (5+enoise(2))) +gnoise(0.02)    // synthesize fake data; here a gaussian curve
       
    endfor
   
    Concatenate/O/NP WaveList("YY*", ";", ""), yData
    Concatenate/O/NP WaveList("XX*", ";", ""), xData
   
    Duplicate/O yData root:yData
    Duplicate/O xData root:xData
   
    Setdatafolder root:
    //KillDataFolder root:tmp
end


and then execute the following commands from the command line

MakeData()
BivariateHist(xdata, ydata, 50, 50, "histWave")
NewImage/K=1  root:histWave
SetAxis/A left
ModifyImage histWave ctab= {*,*,Grays,1}
ColorScale/C/N=text0/S=3/A=MC image=histWave


If I understood correctly, this is what you want.
I think this is the right place for this request... I am hoping to do what I think is a bivariate histogram - bin two sets of time-series data (2 1-d waves) into pre-defined bins in two dimensions (a 2-d wave), but to weight to each count that should go into a bit by a third 1-d wave (on the same time basis as the two data waves).

This is (I think) equivalent to applying the 'weighting' wave in the 1-D 'histogram' command. It doesn't seem that there's way to do this with the 'Bivariate Histogram 2' procedure. Am I missing something, or does anyone have any suggestion about how to apply this functionality, or some other approach to do what I'm asking? I also looked at the 2D Joint Histogram function posted on here, but it doesn't appear to be what I need either. I can just code it, but I figured I'd try here first... Any help would be great.
Thanks!
You're right- Bivariate Histogram 2 doesn't have the weighting capability included. It might be a good place to start to do your own, though.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
agrieshop wrote:
I think this is the right place for this request...


IP7 has a built in multi-dimensional JointHistogram operation.

A.G.
WaveMetrics, Inc.
Ok, it was worth asking... I'll see if I can figure out how to modify 'bivariate histogram 2' to do this, and will look out for the next version...
Thanks!

In reply to by Igor

Hi guy,

How to load the multi-dimensional JointHistogram operation by using IP7?

Best regard

 

Enter and execute on the command line:

displayhelptopic "jointhistogram"