## matplotlib-users

 [Matplotlib-users] sizing shapes on a plot to match axis units, not graphic "points" From: Ian Stokes-Rees - 2010-06-07 15:16:48 ```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@... T: +1 617 432-5608 x75 NEBioGrid, Harvard Medical School C: +1 617 331-5993 ```
 Re: [Matplotlib-users] sizing shapes on a plot to match axis units, not graphic "points" From: Michael Droettboom - 2010-06-07 16:05:02 ```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 ```
 Re: [Matplotlib-users] sizing shapes on a plot to match axis units, not graphic "points" From: Tony S Yu - 2010-06-07 16:17:44 Attachments: text/plain ```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 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 ```