How to plot a density distribution of two variables
이전 댓글 표시
Hello,
i have a huge list of coordinates (x,y) which are often repeated in the list, as you can see from a short cut sample (see attachment):
Since the original huge files creates a surface plot of all these data of (x,y), I would like to plot this surface with the density variation, meaning that I would like to see in the plot where the (x,y) are repeated (high density) and where not.
Can somebody tell me which is the correct function for this?
cheers,
Nino
댓글 수: 1
sixwwwwww
2013년 10월 12일
Dear Nino, attachment is missing. Please try to attach the file once again
답변 (1개)
Hello Nino,
Since the file is not attached, I have used dummy data to reproduce it.
To visualize the density of repeated coordinates in a 2D plot, you can use a 2D histogram with the help of "histogram2" function, available from MATLAB 2015b onwards, as shown below:
% Sample data (replace this with your actual data)
x = [1, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 6];
y = [1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7];
numBinsX = 100;
numBinsY = 100;
figure;
histogram2(x, y, [numBinsX, numBinsY], 'DisplayStyle', 'tile', 'ShowEmptyBins', 'on');
colorbar;
xlabel('X');
ylabel('Y');
title('Density Plot of (x, y) Coordinates');
colormap('hot');
grid on;
axis equal tight;
You can refer to the documentation of 'histogram2' to know more about it using the following command in MATLAB command window :
doc histogram2
Hope this helps!
카테고리
도움말 센터 및 File Exchange에서 Vector Fields에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
