surf() plot adding axis
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone, I have been trying to add axis to a surf plot i have. I've tried various suggestions but can't get it to work. I have 3 matrices:
final -> 3460x300 double
spec -> 1x300 double (x-axis)
timedate -> 1x3460 double (y-axis)
The timedate matrix values are converted time and dates with date2num.
How would pot this with surf and get the spec range on the x-axis and the timedate range on the y-axis. I did surf(final) were the plot looks correct but without the right axis points as in spec and timedate. When i do surf(spec,timedate,final) the plot looks wrong but the axis are correct.
How could i solve this?
Any kind of help would be highly appreciated.
3 commentaires
Mike Garrity
le 22 Juin 2015
In this case, you actually should just be this:
surf(spec,timedate,final,'EdgeColor','none')
It does look like things are nonlinear on the timedate axis. What do you get if you do this?
plot(timedate)
does it look like a straight line,or does the slope change in the middle, or is it non-monotone?
Réponses (2)
Star Strider
le 22 Juin 2015
I’m not certain what you’ve tried, but see if this gives you the result you want:
[SP,TD] = meshgrid(spec, timedate);
surf(SP, TD, final')
grid on
xlabel('spec')
ylabel('timedate')
zlabel('final')
Note the transpose (') in the surf call for your ‘final’ matrix. That’s required because of the way the ‘SP’ and ‘TD’ matrices are created.
2 commentaires
Star Strider
le 22 Juin 2015
I don’t have your data and you didn’t mention missing values before. That may be the reason the matrix dimensions didn’t agree.
You can either use griddedInterpolant to fill in the missing values, or create a (3460x300) matrix of NaN values, then assign the corresponding elements of your ‘final’ matrix to it. The NaN values will not plot.
The scatter3 plot is another option.
Kelly Kearney
le 22 Juin 2015
It appears as though your samples are unevenly spaced in time. So when you plot vs time, certain parts appear squished and stretched compared to the version where you ignore time and assume constant spacing along both axes.
2 commentaires
Kelly Kearney
le 22 Juin 2015
You can fill in the missing portions of the dataset with NaNs. For example:
% Some fake data, with missing time slices
y = 1:300;
t = datenum(2015,1,1) + (0:365);
t(t >= datenum(2015,3,1) & t < datenum(2015,6,1)) = [];
ny = length(y);
nt = length(t);
z = peaks(max(ny,nt));
z = z(1:ny,1:nt);
% The full time vector
t2 = datenum(2015,1,1) + (0:365);
% Add NaNs where needed
[tf,loc] = ismember(t, t2);
znew = nan(ny, length(t2));
znew(:,loc) = z;
surf(t2,y,znew);
shading flat;
Note that this only works if all your t values are in t2. If not, you may have to use a more complicated method.
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!