## 2D Histogram

Marti
Posts: 9
Joined: 2012-04-13
Location: United Kingdom

Hi,
I have a problem to create 2D histogram. I have two data sets: ISIs in ms (0-500 ms, 250 bin, 250 ms binsize; Vm -60- -45mV, 250 bin, 0.1mV binsize) I've tried the commands below:

•make/n=(250,250) myHist
•setscale x,0,500,myHist
•setscale y,-60,-45, myHist
JointHistogram(data1,data2,myHist) or Function JointHistogram(data1,data2,myHist)

but I have an error message. Can anyone help?
Thanks,

Posts: 906
Joined: 2007-06-21
Location: United States

You need to post the JointHistogram function from http://www.igorexchange.com/node/1373 into your procedure window.

Having done that, I was able to successfully execute these commands:

```Make /O /N=1000 xData = 500 * p/1000
Make /O /N=1000 yData = -60 + (15*p/1000)
Make /O /N=(250,250) myHist
SetScale x,0,500,myHist
SetScale y,-60,-45, myHist
JointHistogram(xData,yData,myHist)
NewImage myHist```

Marti
Posts: 9
Joined: 2012-04-13
Location: United Kingdom

Hi,

Yes, thank you very much. Meantime I have found my mistake in the function as well. It works fine in my case too and I got a nice contour plot. I have an other question. How can I normalise the matrix of the results of the 2D Histogram?
Also if I would like to represent the 'density' or the number of dots in each bins and I apply the contour plot how can I set values for the z axe and represent in 3D graph?

Thank you very much for your help,
Marti

Posts: 335
Joined: 2007-06-29
Location: United States

Marti wrote:
How can I normalise the matrix of the results of the 2D Histogram?

You have not defined what you mean by normalization. If you only want the output to sum to 1 then execute:
Variable sss=sum(matrix2d)
Duplicate/O matrix2d,normalized2d // never modify the original
normalized2d/=sss

Marti wrote:
Also if I would like to represent the 'density' or the number of dots in each bins and I apply the contour plot how can I set values for the z axe and represent in 3D graph?

You are not telling us what kind of a 3D graph you want to plot: do you want to plot a surface, a scatter or maybe some kind of a 3D bar chart?

A.G.
WaveMetrics, Inc.

Marti
Posts: 9
Joined: 2012-04-13
Location: United Kingdom

Hi A.G.,
Thank you very much for your help, the normalization works fine.

I'm sorry if I wasn't enough precise, I meant the surface plot as a 3D graph. But you are right the 3D bar chart can be interesting as well.

Thanks,

Marti
Posts: 9
Joined: 2012-04-13
Location: United Kingdom

Hi A.G.

I managed to create the surface plot as well. Thanks!!!!

Marti

A.G.
WaveMetrics, Inc.[/quote]

s.r.chinn
Posts: 173
Joined: 2007-08-16
Location: United States

Marti,

Typically histograms are plotted in a bar-chart mode (although that is partly a matter of taste). AG was perhaps too modest to mention his Gizmo3DBarChart.ipf that comes with Igor, in the Wavemetrics Procedures:Gizmo Procedures folder.

If you don't care for the spacing between bars, then a surface plot will do. Be aware however that standard surface plots interpolate over the grid. If you want flat-topped bins of the histogram in a surface mode, AG had sent me the following procedure for converting to a parametric surface wave:

```Function makeParametric(inWave)
Wave inWave

Variable rows=dimSize(inWave,0)
Variable cols=dimSize(inWave,1)
Variable i,j,val

Make/N=(2*rows,2*cols,3)/O paramWave
// fill the x-values
Variable x0=dimOffset(inWave,0)
Variable dx=dimDelta(inWave,0)
Variable curx=x0
for(i=0;i<rows;i+=1)
paramWave[2*i][][0]=curX
paramWave[2*i+1][][0]=curX+dx
curX+=dx
endfor

// fill the y-values
Variable y0=dimOffset(inWave,1)
Variable dy=dimDelta(inWave,1)
Variable cury=y0
for(i=0;i<cols;i+=1)
paramWave[][2*i][1]=curY
paramWave[][2*i+1][1]=curY+dy
curY+=dy
endfor

// fill the z-values
for(i=0;i<rows;i+=1)
for(j=0;j<cols;j+=1)
val=inWave[i][j]
paramWave[2*i][2*j][2]=val
paramWave[2*i+1][2*j][2]=val
paramWave[2*i][2*j+1][2]=val
paramWave[2*i+1][2*j+1][2]=val
endfor
endfor

End```