Smoothed 2D histogram contour
31 ビュー (過去 30 日間)
古いコメントを表示
I want to plot smoothed 2D histogram contour with the help of X & Y data, I have attached excel file of same. I was only able to plot 2D histogram. how can I add contour ?
x = importdata('x.txt');
>> y = importdata('y.txt');
>> data=[x,y];
>> hist3(data,cdatamode,'auto')
I need this type of smoothed plot
3 件のコメント
Ive J
2022 年 1 月 23 日
編集済み: Ive J
2022 年 1 月 23 日
data = readtable('https://se.mathworks.com/matlabcentral/answers/uploaded_files/870630/xy.xlsx');
histogram2(data.X, data.Y, 'DisplayStyle', 'tile', 'NumBins', 250)
shading interp
grid off
Another example:
h = histogram2(randn(1e6, 1), randn(1e6, 1), 'DisplayStyle', 'tile', 'NumBins', 200);
shading interp
回答 (1 件)
Simon Chan
2022 年 1 月 23 日
Try this:
data = readmatrix('xy.xlsx');
nbins=[200 200]; % You may adjust number of bins for both direction
[N,Xedges,Yedges] = histcounts2(data(:,1),data(:,2),nbins);
[X,Y] = meshgrid(Xedges(1:end-1),Yedges(1:end-1));
N = N';
scatter(X(:),Y(:),[],N(:),'filled'); % Use scatter plot
colorbar; % Colorbar with custom colormap
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!