Using datetime in surf plot
8 views (last 30 days)
Show older comments
stuckinthemuck
on 30 Jan 2015
Commented: Star Strider
on 25 Apr 2025
I have a bunch of subplots that are linked with linkaxes and I currently use the FEX function dynamicDateTicks to update the tick labels when I zoom. BUT. The new datetime format looks better (less crowded) on the graphs. Only I can't get it (datetime) to work with a surf plot.
Here's a minimal working example:
X = 25:25:100;
T = datenum(2015,01,01,1:4,0,0);
Z = [ 1 2 3 4;
5 6 7 8;
9 10 11 12;
13 14 15 16];
[Xmesh,Tmesh] = meshgrid(X,T);
% Tmesh = datetime(Tmesh,'ConvertFrom','datenum');
figure;
surf(Tmesh,Xmesh,Z);
If you uncomment the one line, this gives me the error:
Error using surf (line 57)
X, Y, Z, and C cannot be complex.
Anyone else have this problem? It seems like a bug, since it works fine with any other plot. For example:
plot(datetime(2014,01,1:2),1:2)
Any help would be appreciated. And just to be clear, I currently can get it all to work with dynamicDateTicks (datetick), I'm just hoping for a cleaner plot.
0 Comments
Accepted Answer
Star Strider
on 30 Jan 2015
I can’t find it in the documentation just now, but datetime doesn’t work with ‘surface’ plots. It works with 2D plots only.
I believe datetick will still work on ‘surface’ plots.
4 Comments
Guilherme de Melo
on 25 Apr 2025
Hello Star Strider. My MATLAB 2020 continue not work the datetick with surf command. Do you have some update about how to plot the time with surf? I was trying from my following question: https://www.mathworks.com/matlabcentral/answers/2176629-how-to-improve-spectrogram-plot Thanks in advance.
Star Strider
on 25 Apr 2025
@Guilherme de Melo — Use datetime not datetick. I don't remember if it was possible to use datetime arrays in surf plots in R2020a or R2020b, and I no longer have access to that release. I believe datetime works with surf plots currently.
More Answers (0)
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!