 # sizing shapes on a plot to match axis units, not graphic "points"

I'm generating a plot of NxN squares, where the size of the square
corresponds to the correlation between the (i,j) point. Every (i,i)
point equals 1.0. I'm using "scatter" to do this, but the sizing
appears to be in "points" from the graphic, rather than "units" of the
two axes. Is there some way to account for this, or is there some
better way to generate this image?

# result = n x n matrix of correlations between points (i,j)
a = arange(n).repeat(n).reshape(n,n)
b = a.transpose()
scatter(a.flatten(), b.flatten(), s=result, marker='s')

You can see an example here, where N=300: (note, this is a 2.5 MB image):

http://abitibi.sbgrid.org/se/data/shared/biodb/scop-class/a/39/1/5/.meta/tmscore2.png

Thanks,

Ian

···

--
Ian Stokes-Rees, PhD W: http://hkl.hms.harvard.edu
ijstokes@...3143... T: +1 617 432-5608 x75
NEBioGrid, Harvard Medical School C: +1 617 331-5993

Since this data is essentially a 2 dimensional image, you may want to experiment with imshow.

Mike

···

On 06/07/2010 11:16 AM, Ian Stokes-Rees wrote:

I'm generating a plot of NxN squares, where the size of the square
corresponds to the correlation between the (i,j) point. Every (i,i)
point equals 1.0. I'm using "scatter" to do this, but the sizing
appears to be in "points" from the graphic, rather than "units" of the
two axes. Is there some way to account for this, or is there some
better way to generate this image?

# result = n x n matrix of correlations between points (i,j)
a = arange(n).repeat(n).reshape(n,n)
b = a.transpose()
scatter(a.flatten(), b.flatten(), s=result, marker='s')

You can see an example here, where N=300: (note, this is a 2.5 MB image):

http://abitibi.sbgrid.org/se/data/shared/biodb/scop-class/a/39/1/5/.meta/tmscore2.png

Thanks,

Ian

--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

What you’re doing sounds very similar to a Hinton diagrom (or at least the resulting image looks similar). There’s an example of plotting such a diagram in the scipy cookbook:

http://www.scipy.org/Cookbook/Matplotlib/HintonDiagrams

The implementation is pretty slow because it loops through the data and draws each square one by one. I wrote a faster alternative a while back (see attached). It uses a custom PolyCollection, which uses data units for the areas instead of figure units. Also, I just noticed there’s another implementation of Hinton diagrams in the matplotlib examples folder (examples/api/hinton_demo.py). For some reason, this example doesn’t appear on the website, otherwise I’d link to it.

I believe the difference between your plot and a hinton diagram is that you have a different metric for calculating the size of the squares.

-Tony

hinton.py (2.08 KB)

···

On Jun 7, 2010, at 11:16 AM, Ian Stokes-Rees wrote:

I’m generating a plot of NxN squares, where the size of the square
corresponds to the correlation between the (i,j) point. Every (i,i)
point equals 1.0. I’m using “scatter” to do this, but the sizing
appears to be in “points” from the graphic, rather than “units” of the
two axes. Is there some way to account for this, or is there some
better way to generate this image?

# result = n x n matrix of correlations between points (i,j)

a = arange(n).repeat(n).reshape(n,n)
b = a.transpose()
scatter(a.flatten(), b.flatten(), s=result, marker=‘s’)

You can see an example here, where N=300: (note, this is a 2.5 MB image):

http://abitibi.sbgrid.org/se/data/shared/biodb/scop-class/a/39/1/5/.meta/tmscore2.png

Thanks,

Ian