For the y axis issue and to write your own ranges along the axes, you may modify the DataDensityPlot function as follows:
function [ f ] = DataDensityPlot( x, y, levels, limits)
map = dataDensity(x, y, 256, 256, limits);
map = map - min(min(map));
map = floor(map ./ max(max(map)) * (levels-1));
f = figure();
image(map);
colormap(jet(levels));
if(nargin == 4)
set(gca, 'XTick', [1 256]); % --
set(gca, 'XTickLabel', [limits(1) limits(2)]); % --
set(gca, 'YTick', [1 256]); % --
set(gca, 'YTickLabel', [limits(3) limits(4)]); % --
set(gca, 'YDir', 'normal'); % --
else
set(gca, 'XTick', [1 256]);
set(gca, 'XTickLabel', [min(x) max(x)]);
set(gca, 'YTick', [1 256]);
set(gca, 'YTickLabel', [min(y) max(y)]);
end
uiwait;
end
---------------------
It may then be called for instance as follows:
limits = [1 4 1 4];
DataDensityPlot(x, y, 100, limits);
---------------------
If you have weights associated to your data points, you can transform your x and y vectors before feeding them to DataDensityPlot function as follows:
function [wx, wy] = WeightedDensityTransform(x, y, weights)
if (isequal(size(x),size(y),size(weights)) == 0)
error('The input vectors must have the same dimensions');
end
sizeX = size(x);
length = sizeX(2);
index=0;
for i=1:1:length
depth = round(weights(i));
index=index+1;
wx(index) = x(i);
wy(index) = y(i);
if (depth > 1)
for j=1:1:depth-1
index = index + 1;
wx(index) = x(i);
wy(index) = y(i);
end;
end;
end;
end
---------------------
You may then call it in the following way:
[wx, wy] = WeightedDensityTransform(x,y, w);
limits = [1 4 1 4];
DataDensityPlot(wx, wy, 100, limits);
Comment only
08 Apr 2013
Data density plot
Plots data density of a two-dimensional distribution for human viewing.
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?
Comment only
25 Apr 2012
Data density plot
Plots data density of a two-dimensional distribution for human viewing.
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.
Comment only