Fri, 03/12/2010 - 10:44 pm
I have a 2D array of point corrdinates in the x,y plane. I would like to produce a contour plot which displays the density of the point distribution in the plane. Is this possible? How? I have been playing with Igor for about two hours so I'll need pretty simple instructions. Thanks
DN
A dialog box will come up. The Z-wave should be your array and the x and y should be calculated from your point scaling.
Click "Do It". Right click on the plot to modify the graph.
Andy
March 13, 2010 at 06:08 pm - Permalink
March 13, 2010 at 10:46 pm - Permalink
When you create a contour of a matrix of Z values using explicit X and Y waves, the X and Y waves must have one extra point. This is because, for example, the X wave specifies the X coordinate of the left edge of each pixel in the matrix and Igor needs to know the X coordinate of the right edge of the last pixel. Use explicit X and Y waves only if your data is unevenly spaced.
If your data is evenly-spaced, choose _calculated_ for X wave and Y wave and set the X and Y scaling of the matrix of Z values to indicate what the spacing is. To set the X and Y scaling, choose Data->Change Wave Scaling.
If you do have unevenly-spaced Z data then you must add an extra point to your X and Y waves. The extra point should specify the X or Y coordinate of the right edge of the last pixel in the matrix of Z values. You can add the extra point using a table.
April 1, 2010 at 02:14 pm - Permalink
Each value in the array is specified to two decimals (only). So, do I need to sort the array, and how do I work out the value of the additional point you mention?
Thanks
March 13, 2010 at 11:40 pm - Permalink
I'm not tracking.
To create a contour plot in Igor you need either a matrix (2D wave) of Z values or a series of XYZ triplets. Your latest post does not mention a matrix and does not mention a Z wave. Do you have a matrix of Z values or a series of XYZ triplets?
March 14, 2010 at 12:00 am - Permalink
ModifyGraph mode=3 // Markers mode
If you have XYZ data, whether in the form of a matrix of Z values or XYZ triplets, try checking out the Contour Demo experiment by choosing File->Example Experiments->Contour Demo. This may help you understand what Igor is looking for.
Here is another simple example using a matrix of Z values:
SetScale x -1, 1, mat
SetScale y -1, 1, mat
mat = x * y
Edit mat
NewImage mat
Display;AppendMatrixContour mat
AppendImage mat
March 14, 2010 at 12:30 am - Permalink
When I tried the command:
Display yData vs xData
Igor replied "expected Wave name".
Algorithmically, I can think of one way of doing it, namely for a regularly spaced set of cells of width dx,dy, spanning the same x,y range as the original data set, for each cell in the array, how many objects in the original data set are there within each cell, and set that value as the 'z' value for the x,y cell, then use that as the basis for contour drawing. But I was hoping Igor might have something like that built in.
March 14, 2010 at 03:29 am - Permalink
In this case you can not do a contour plot. A contour plot requires X, Y and Z values and you have only X and Y values.
I don't know how to do that. Perhaps someone else will have an idea.
You need to replace yData and xData with the names of your Y and X waves.
Yes, that would work. I don't believe Igor has anything built-in.
I have attempted to write a function that does this. It is not thoroughly tested. You can find it here. Copy and paste it to the procedure window of a new experiment and try the example commands in the comments. Then read the function to get a sense of how it works.
March 14, 2010 at 11:05 am - Permalink
I just coded this little function, looks quite similar to what Howard did. In my case, you can only specify a square grid and the name of the output matrix is hardcoded. But the result is a little different...so I post it anyway.
Wolfgang Harneit
wave xWave, yWave
variable nIntervals
variable nPnts = min(numpnts(xWave), numpnts(yWave))
variable xMin = WaveMin(xWave), yMin = WaveMin(yWave)
variable xMax = WaveMax(xWave), yMax = WaveMax(yWave)
Make/O/N=(nIntervals, nIntervals) mat
SetScale/I x, xMin, xMax, mat
SetScale/I y, yMin, yMax, mat
Duplicate/FREE/O xWave, xSorted
Duplicate/FREE/O yWave, ySorted
Redimension/N=(nPnts) xSorted, ySorted
xSorted = round((xSorted - xMin) * nIntervals / (xMax-xMin))
ySorted = round((ySorted - yMin) * nIntervals / (yMax-yMin))
Sort {xSorted, ySorted} xSorted, ySorted
variable n, nx = 0, ny = 0
for( n = 0; n < nPnts; n += 1)
if( (ySorted[n] > ny) || (xSorted[n] > nx) )
nx = xSorted[n]
ny = ySorted[n]
endif
mat[nx][ny] += 1
endfor
end
A sample call is
•Display yData vs xData
•ModifyGraph mode(yData)=2
•pntDensity(xData, yData, 10)
•AppendMatrixContour mat
March 14, 2010 at 12:49 pm - Permalink
March 14, 2010 at 05:44 pm - Permalink
March 14, 2010 at 06:01 pm - Permalink
I've just begun to appreciate the power of Igor!
Thanks to all for guidance.
March 14, 2010 at 09:39 pm - Permalink
And I think that 2D Joint Histogram is faster and cleverer than my own code that ships with Igor. For mine, add this line to your Procedure window:
There are comments describing the file at the top; select Windows->Procedure Windows->Bivariate Histogram 2.ipf. My procedure adds a bit of GUI to the problem.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
March 18, 2010 at 01:26 pm - Permalink
Curious Browser or bulletin board quirk: I cannot see the <Bivariate Histogram 2> term in Safari that follows the "#include"
I only saw it when I quoted the original to ask what was included! (So question answered itself!)
I used the HTML codes > and < to show it in my post
DN
March 19, 2010 at 04:48 am - Permalink
This is because John forgot to surround his Igor code with <igor></igor> tags. I just fixed his original post so it looks right again.
March 19, 2010 at 08:52 am - Permalink