Clear Filters
Clear Filters

I would like to plot several histograms in 3D using Matlab like in the below figure. Does anyone have any suggestions?

1 view (last 30 days)

Answers (2)

Cameron
Cameron on 23 Feb 2023
  1 Comment
Heri
Heri on 25 Feb 2023
Thanks for your answer, Cameron. You suggest to check out a solution using fill3. However, the way to plot several histograms is different from fill3 command, since syntax for bar3, histogram2, hist3 is not like fill3 which uses 3 vectors, i.e., X, Y, and Z in each coordinate axis.

Sign in to comment.


DGM
DGM on 26 Feb 2023
Edited: DGM on 26 Feb 2023
I could have sworn I'd posted an answer to a similar problem, but maybe I'm dreaming. Here's one way of doing it with bar3().
% say you have some data
% i'm just going to use channel histograms from an image
inpict = imread('peppers.png');
nbins = 64;
counts = zeros(nbins,3);
for c = 1:3
[counts(:,c),~] = imhist(inpict(:,:,c),nbins);
end
% plot them using bar3()
xoffset = [0 10 20];
alpha = 0.5;
hb = bar3(counts);
for k = 1:numel(hb)
hb(k).XData(:) = xoffset(k);
hb(k).FaceAlpha = alpha;
hb(k).LineStyle = 'none';
end
xticks(xoffset)
colormap(hsv(numel(hb))) % or pick whatever map you want
% adjust dataaspect to force spacing on x
xscalefactor = 2; % adjust me
yl = ylim; % store for later
hax = gca;
hax.DataAspectRatio(1) = hax.DataAspectRatio(1)/xscalefactor;
% clean up view
ylim(yl)
xlim(xoffset([1 end]))
view(-55,20)
While bar3 allows a Y parameter, that seems to really only be useful for setting the position of data groups, not series. Given that, I don't see a simple way to do this without a bunch of direct manipulation of the individual surf objects.

Community Treasure Hunt

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

Start Hunting!