Code covered by the BSD License  

Highlights from
Data density plot

3.85714

3.9 | 7 ratings Rate this file 52 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.

Acknowledgements

This file inspired Data Density Plot2.

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File  
Everyone's Tags
data density(4), statistics, visualization
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
08 Apr 2013 Jeremy

http://www.mathworks.com/matlabcentral/fileexchange/41185-datadensityplot2d

08 Apr 2013 Jeremy

Functional, but a bit slow. I wrote a similar function using hist3 to perform the density calculation, runs a million samples in less than a second.

19 Oct 2012 Nina

Great in it does what I want, but I have the same problem with the yaxis reversed and matlab frozen while window open. Is there an improved or similar function?

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.

31 Jan 2012 Mehdi Moghaddam

super slow:(

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.

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.

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!

19 Jun 2011 Alexander Kosenkov  
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.

Contact us