smooth the surf or pcolor graph

조회 수: 13(최근 30일)
Abdulkarim Almukdad
Abdulkarim Almukdad 2021년 3월 2일
댓글: Mathieu NOE 2021년 3월 3일
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]);

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 3월 2일
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
Mathieu NOE
Mathieu NOE 2021년 3월 3일
You're welcome !

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by