How can I make the surface plot (surf) look less shifty between plotted distributions?

26 views (last 30 days)
Hello,
I'm trying to make a surface plot that shows average growth factor distributions per 4hrs over multiple days. The growth factors come from "dia" and the "fits" are the distribution part/number fraction seen in that bin. I am able to make the surf plot, but I'm trying to not have it do that weird slide up or down that is sometimes seen in between some of the scans. I'd rather it just show the previous distribution throughout the whole time frame until the next distribution is, then it switch to that. I'm pretty bad at verbally explaining it, and so I attached a photo of the plot with arrows pointing to what I don't want to see and to what I do want to see. Hopefully there is a way to fix this issue or at least a different type of plot that maybe would give the results I'm looking for.
The code for it is below and I attached the table used to make this plot:
load 'Data_tbl used in question.mat'
% Set Individual Variables
dia = data_tbl.Dia;
fit = data_tbl.Fit;
time = data_tbl.Time;
figure('Position',[10 10 1400 400])
surf((dia./100),time,fit,'EdgeColor','none') % divided by 100 to get growth factor instead of diameter
hold on
colormap("turbo")
view([90,-90]);
xlim([0.75 2.5])
xlabel("GFs"); zlabel("Diameter (nm)");
c = colorbar('Location','eastoutside');
ylabel(c,"CPCA Conc:CPCB Conc.");
ylim([time(1,1) time(end,1)])
title(setRH(:,rh) + "% RH at 100 nm for " + string(time(1,1),"MMM d, uuuu hh:mm aa") + "-" + string(time(end,1),"MMM d, uuuu hh:mm aa"));
Unrecognized function or variable 'setRH'.
Let me know if something seems like its missing or if more clarification is needed.
Thank you!

Accepted Answer

Mathieu NOE
Mathieu NOE on 13 Jun 2025 at 9:49
hello
It took me some time to understand what causes these "slides"
what was a bit annoying me is that your X data (dia matrix) contains vectors that are always fluctuating in some manner , even though they cover more or less the same range
so what I tried is to convert / interpolate the fit data vs a constant and fixed dia vector , and fortunately , the new (second plot) does not show anymore those strange zig zags
of course you could even add a bit of smoothing along the x direction if you wanted (up to you)
load 'Data_tbl used in question.mat'
% Set Individual Variables
dia = data_tbl.Dia;
fit = data_tbl.Fit;
time = data_tbl.Time;
% do some interpolation of fit data vs new_dia array
% rows of NaN or zeros are kept as in the original data
[m,n] = size(fit);
tmp = unique(dia(:));
tmp = tmp(tmp>0);
new_dia = linspace(min(tmp),max(tmp),n);
newfit = NaN(m,n);
indnan = find(isnan(dia(:,1)));
indzero = find(abs(dia(:,1))<eps);
indk = 1:m;
indk([indnan; indzero]) = [];
for c = 1:numel(indk)
k = indk(c);
x = dia(k,:);
y = fit(k,:);
[xu,iu] = unique(x);
yu = y(iu);
newfit(k,:) = interp1(xu,yu,new_dia);
end
% original plot
figure('Position',[10 10 1400 400])
surf((dia./100),time,fit,'EdgeColor','none') % divided by 100 to get growth factor instead of diameter
hold on
colormap("turbo")
view([90,-90]);
xlim([0.75 2.5])
xlabel("GFs"); zlabel("Diameter (nm)");
c = colorbar('Location','eastoutside');
ylabel(c,"CPCA Conc:CPCB Conc.");
% ylim([time(1,1) time(end,1)])
% modified data plot
figure('Position',[10 10 1400 400])
surf(new_dia/100,time,newfit,'EdgeColor','none') % divided by 100 to get growth factor instead of diameter
hold on
colormap("turbo")
view([90,-90]);
xlim([0.75 2.5])
xlabel("GFs"); zlabel("Diameter (nm)");
c = colorbar('Location','eastoutside');
ylabel(c,"CPCA Conc:CPCB Conc.");
% ylim([time(1,1) time(end,1)])
  2 Comments
Mara
Mara on 13 Jun 2025 at 13:22
The figure looks so much better now! I wasn't sure how interpolations worked, but this makes sense to me. Thank you so much for your help! :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!