smooth the surf or pcolor graph

6 views (last 30 days)
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]);

Accepted Answer

Mathieu NOE
Mathieu NOE on 2 Mar 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 Comments
Abdulkarim Almukdad
Abdulkarim Almukdad on 3 Mar 2021
Thank you very much I highly really appreciate your responses.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!