2D Histograms in Planes XZ, YZ

3 views (last 30 days)
Manuel
Manuel on 6 Feb 2014
Answered: Manuel on 7 Feb 2014
Hello, I am trying to get a representation similar to the one attached to this message. That is to say, I would like to represent two 2D-histogram, one in the plane XZ and the other in the plane YZ. In X and Y, the magnitude to be displayed is the same, but the thing is that the Z-axis is different. As I want to make the representation clearer, I would add additional information in the plane Z=0, that is the reason for which I have not used the 2D-histogram with two different Y-axes. It would be very nice if you could help me to solve this. Thanks in advance, Manuel.

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 6 Feb 2014
OK, here's a simple example where you plot a few pieces together...
% First some "test-data":
x = randn(500,1);
x = x-min(x)+0.5;
y = randn(500,1);
y = y-min(y)+0.5;
y = y.^1.5+1*x;
z = exp(-abs(2*x-y)/4); % Just to get something similar to the figure linked to in your reference
[Nx,xH] = hist(x,9); % Histogram of X-values
[Ny,yH] = hist(y,11); % and Y
dX = gradient(xH); % Spacing between histogram bin centres
dY = gradient(yH);
%%Plot stuff...
scatter3(x,y,z,15,z,'filled') % The points
for i1 = 1:length(xH), % And the X-histogram bars
pHmyX(i1) = patch(xH(i1)+dX(i1)*[-1 1 1 -1 -1]/2,...
[0 0 0 0 0],...
[0 0 Nx(i1)*[1 1] 0],rand(1,3));
end
for i1 = 1:length(yH),
pHmyY(i1) = patch([0 0 0 0 0],...
yH(i1)+dY(i1)*0.9*[-1 1 1 -1 -1]/2,...
[0 0 Ny(i1)*[1 1] 0],rand(1,3));
end
You should be able to modify and extend that to suit your needs.
HTH

More Answers (4)

Manuel
Manuel on 6 Feb 2014
Sorry. The plot appears in this link:

Bjorn Gustavsson
Bjorn Gustavsson on 6 Feb 2014
Well, have you tried what Walter suggested in his reply in the thread you linked to? Should work, then with the 2 histograms in the XZ and YZ planes you can continue to plot whatever you wanted...
HTH
  1 Comment
Manuel
Manuel on 6 Feb 2014
Thank you for your answer, Bjorn. Yes, I have tried to do what Walter proposed, but I am quite new in Matlab and I am having some problems facing this. I think that any simple code as example would help me a lot to see what Walter suggests in his answer.

Sign in to comment.


Manuel
Manuel on 7 Feb 2014
Thank you very much, Bjorn.

Manuel
Manuel on 7 Feb 2014
As an alternative to what Bjorn has proposed, I would like to say that I got something similar to this using the command "fill3(X,Y,Z,COLOR)" and defining previously in X, Y and Z the coordinates of the bars (so, if I want to project the histogram in the plane XZ, the only thing I have to do is defining always Y=0). In my case, I projected two histograms using this "fill3" function, and then I plotted a 3-D bar graph with the colormap using "bar3color" (instead of a scatter plot, as in the previous example). Regards.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!