3D Histogram of 50x50 data

8 次查看(过去 30 天)
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.

采纳的回答

the cyclist
the cyclist 2023-6-3
You can make this style of plot using the histogram2 function.
  3 个评论
the cyclist
the cyclist 2023-6-3
% 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])
AS
AS 2023-6-3
awesome, thank you very much!!

请先登录,再进行评论。

更多回答(1 个)

Diwakar Diwakar
Diwakar Diwakar 2023-6-4
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

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by