Code covered by the BSD License  

Highlights from
Data density plot

3.83333

3.8 | 6 ratings Rate this file 47 Downloads (last 30 days) File Size: 2.45 KB File ID: #31726
image thumbnail

Data density plot

by Malcolm McLean

 

08 Jun 2011

Plots data density of a two-dimensional distribution for human viewing.

| Watch this File

File Information
Description

Data density can be hard to read from scatter plots due to overstriking. I therefore calculate data density at each pixel as the reciprocal of the sum of squared distance from each point, adding a fudge factor to prevent points actually within the pixel going to infinity.

The resulting plot allow for a visual fix on data density.

MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
10 Jun 2011 bmv

Replace this part "for kk = 1: length(x)"
to this:
"parfor kk = 1: length(x)"
This will help speed up the computation for multicore systems after running matlabpool.

19 Jun 2011 Alexander Kosenkov  
04 Aug 2011 J G

Good function! Would it work for one-dimensional data, ie. a vector? I am using hist(Y) but would prefer to show the density like this... Thanks!

04 Aug 2011 Malcolm McLean

J G. Yes. Just pass in a dimension of one pixel for the y axis, and it ought to provide you with a data density plot. You'll have to stretch the image to see it.

09 Jan 2012 Jason Kaeding

Very slow. Don't replace the kk loop with parfor as bmv suggests, just vectorize the calculation and get rid of the loop:

dmap(ii+1, jj+1) = sum( 1./ ( (x - xi).^2 + (y - yi).^2 + fudge) );

The other loops can be vectorized as well if you use bsxfun.

31 Jan 2012 Mehdi Moghaddam

super slow:(

25 Apr 2012 Ben Ruppel

Great tool, but maybe it should flip the y-axis so the results aren't upside down. Also, Matlab stays frozen in a busy state as long as the result figure is open. Need to close the figure before I can do anything else.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
data density Malcolm McLean 08 Jun 2011 16:27:03
visualization Malcolm McLean 08 Jun 2011 16:27:03
statistics Malcolm McLean 08 Jun 2011 16:27:03
data density C Mitchell 03 Aug 2011 22:25:15

Contact us at files@mathworks.com