3D Histogram of 50x50 data
6 views (last 30 days)
Show older comments
Hello, I am looking to plot a 3D histogram (like the one in the attached snippet) in MATLAB. I have x and y axes which are 50 bins each, one is ranging from -4000 and 4000 and the other one from 0 and 8000. I just need to plot the binned values (as z) which is 50x50.
Thanks in advance.
0 Comments
Accepted Answer
the cyclist
on 3 Jun 2023
3 Comments
the cyclist
on 3 Jun 2023
% Read the data from file
xyz = readmatrix("Histogram2_sample.xlsx");
% Get the x, y, and z values
x = xyz(2:end,1);
y = xyz(1,2:end)'; % Transpose to get a column vector
z = xyz(2:end,2:end);
% Flip x and z, because histogram algorithm requires increasing values
x = flipud(x);
z = flipud(z);
% Plot
figure
histogram2('XBinEdges',[x; x(end)+160],'YBinEdges',[y; y(end)+160],'BinCounts',z)
% Change the view to make the perspective similar to posted image
set(gca,"View",[145 30])
More Answers (1)
Diwakar Diwakar
on 4 Jun 2023
This code may help you:
% Generate some random data
data = randn(1000, 2) .* [4000, 8000] + [0, 4000];
% Define the bin edges
x_edges = linspace(-4000, 4000, 51);
y_edges = linspace(0, 8000, 51);
% Compute the histogram
histogram2D = hist3(data, 'Edges', {x_edges, y_edges});
% Plot the 3D histogram
figure;
bar3(histogram2D);
xlabel('X');
ylabel('Y');
zlabel('Count');
title('3D Histogram');
% Customize the plot appearance
colormap jet; % Change the color map if desired
colorbar; % Add a color bar
0 Comments
See Also
Categories
Find more on Histograms 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!