How to plot a density distribution of two variables
11 ビュー (過去 30 日間)
古いコメントを表示
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 件)
nick
2025 年 2 月 20 日
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!
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
