
smooth the surf or pcolor graph
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Abdulkarim Almukdad
am 2 Mär. 2021
Kommentiert: Mathieu NOE
am 3 Mär. 2021
I having a trouble in making my graph more clear and smooth in other words, make the locations with high value of Z be much more clear or distributed among the adjacent points soth that it can be obvious that at certain location we have high Z. a sample of my data is attached and the below is the code I'm using. the attached figure is what I'm really looking for to have. Thanks in advance

num = readtable("01)90.xlsx") ;
% Take all the data under each variable name
x=num{1:1:end, contains(num.Properties.VariableNames, 'x')};
y=num{1:1:end, contains(num.Properties.VariableNames, 'y')};
z=num{1:1:end, contains(num.Properties.VariableNames, 'v')};
% Convert the matrix to 1 column only (scalar)
x=x(:);
y=y(:);
z=z(:);
% Delete rows that contain NaNs with reference to the variable z
i=1; [m,n]=size(x);
while i<=m
if isnan(z(i,1))
x(i,:)=[];
y(i,:)=[];
z(i,:)=[];
i=i-1;
end
i=i+1; [m,n]=size(x);
end
x0 = min(x) ; x1 = max(x) ;
y0 = min(y) ; y1 = max(y) ;
xi = linspace(x0,x1,100) ;
yi = linspace(y0,y1,100) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
% Get boundary coordinates
idx = boundary(x,y) ;
xb = x(idx) ; yb = y(idx) ;
% Get points lying inside the boundary
idx = inpolygon(X,Y,xb,yb) ;
Z(~idx) = NaN ;
f=pcolor(X,Y,Z);
colorbar
shading interp
axis([-800 800 -800 800]);
0 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 2 Mär. 2021
hello
looking first at your data distribution (histogram(Z)) I noticed 90% of the data is between 15 and 300 , very few samples are present above 300 so a linear colorbar was in my mind not the optimal choice
so the next idea was to plot the data with a log scaled colorbar . This is how the result looks now :

code is below :
clc
close all
clear all
num = readtable("01)90.xlsx") ;
% Take all the data under each variable name
x=num{1:1:end, contains(num.Properties.VariableNames, 'x')};
y=num{1:1:end, contains(num.Properties.VariableNames, 'y')};
z=num{1:1:end, contains(num.Properties.VariableNames, 'v')};
% Convert the matrix to 1 column only (scalar)
x=x(:);
y=y(:);
z=z(:);
% Delete rows that contain NaNs with reference to the variable z
i=1; [m,n]=size(x);
while i<=m
if isnan(z(i,1))
x(i,:)=[];
y(i,:)=[];
z(i,:)=[];
i=i-1;
end
i=i+1; [m,n]=size(x);
end
x0 = min(x) ; x1 = max(x) ;
y0 = min(y) ; y1 = max(y) ;
xi = linspace(x0,x1,100) ;
yi = linspace(y0,y1,100) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
% Get boundary coordinates
idx = boundary(x,y) ;
xb = x(idx) ; yb = y(idx) ;
% Get points lying inside the boundary
idx = inpolygon(X,Y,xb,yb) ;
Z(~idx) = NaN ;
f=pcolor(X,Y,log10(Z));
N = 32; % colorbar discrete values
cmap = colormap(jet(N)) ; %Create Colormap
cbh = colorbar ; %Create Colorbar
cbh.Ticks = linspace(min(log10(Z),[],'all'), max(log10(Z),[],'all'), N) ; %Create N ticks from min to max of Z array
tmp = round(logspace(log10(min(Z,[],'all')), log10(max(Z,[],'all')), N));
cbh.TickLabels = num2cell(tmp) ; %Replace the labels of these N ticks with the numbers defined in "tmp"
shading interp
axis([-800 800 -800 800]);
9 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


