3D Histogram of 50x50 data

조회 수: 8 (최근 30일)
AS
AS 2023년 6월 3일
답변: Diwakar Diwakar 2023년 6월 4일
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