Smoothed 2D histogram contour

조회 수: 31 (최근 30일)
Rohit Gaikwad
Rohit Gaikwad 2022년 1월 23일
편집: Ive J 2022년 1월 23일
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
Rohit Gaikwad
Rohit Gaikwad 2022년 1월 23일
How can I create smoothed plot like this
Ive J
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
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

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by