Smoothed 2D histogram contour

31 visualizzazioni (ultimi 30 giorni)
Rohit Gaikwad
Rohit Gaikwad il 23 Gen 2022
Modificato: Ive J il 23 Gen 2022
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 Commenti
Rohit Gaikwad
Rohit Gaikwad il 23 Gen 2022
How can I create smoothed plot like this
Ive J
Ive J il 23 Gen 2022
Modificato: Ive J il 23 Gen 2022
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

Accedi per commentare.

Risposte (1)

Simon Chan
Simon Chan il 23 Gen 2022
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

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by