Histogram and density plot together -- does not match each other

Hello Good People, I have been trying to plot histogram and density plot for a certain data set. But my histogram and density plot do not agree with each other. Can anyone please help me out of this. I am using the following code:
x = rand(1,1000)';
y = randn(1,1000)';
N = hist3([x,y],bins);
N(size(N,1)+1,size(N,2)+1) = 0;
xb = linspace(min(x),max(x),size(N,1));
yb = linspace(min(y),max(y),size(N,2));
hist3([x,y],'Nbins',bins,'CDataMode','auto','FaceColor','interp')
xlabel('X')
ylabel('Y')
hold on
h = pcolor(xb,yb,N)
colormap('hot')
h.ZData = ones(size(N))*-max(max(N));
ax = gca;
ax.ZTick(ax.ZTick < 0) = [];
The picture on the left is showing the density plot and histogram together. The picture on the right is showing the the top view of the histogram. Which does not consistent with density plot on the left.

Antworten (0)

Gefragt:

am 16 Apr. 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by