Plotting time/date on surf or mesh plot

2 次查看(过去 30 天)
I'm trying to plot time&date on a surface but can't get it to look right. It's a time period between 1920-2019 where measurements are scattered in between those years, som years more measurements than other years. Dates where in Julian days to start with and have been converted to datetime. Which I have tried to plot it in, but couldnt get to work.
After that, I tried with just years. This looked fine on the labels, but with all the data from that year in spot didnt look very representative. I also tried converting YYMMDD format and it didn't look very good either.
Any advice on how i could do this? It would be greatly appreciated.
  4 个评论
dpb
dpb 2020-4-12
Again, we can't debug explanations -- show us the exact code you used.
If you plot on a numeric axis, whether it's old datenum or newfangled datetime, the actual data points will be plotted where they fall on the axis--the ticks and tick labels are functions of the axis display only.
How you got 1.96 1.965 1.97 as x-axis tick marks is indicative you plotted year/1000 instead of year or somehow else wrote a ticklabel that doesn't represent the actual year but year/1000.
AGAIN, ATTACH SOME DATA if you expect somebody to be able to really do anything...but w/o code itself it's all just the proverbial "Crystal Orb Toolbox" time....and as I'm know to oft complain my version is in the shop again for repairs.

请先登录,再进行评论。

采纳的回答

Steven Lord
Steven Lord 2020-4-11
surf can handle datetime and duration data. Let's create some sample datetime data and use that to compute a duration.
[d1, d2] = meshgrid(datetime('now')+days(0:10));
z = d1-d2;
Plot it as a surface.
h = surf(d1, d2, z);
I would prefer the Z axis labels to be in units of days rather than hours, minutes, and seconds. Let's change the format on those labels. First we need to get the axes that contains the surface plot.
ax = ancestor(h, 'axes');
Now set the format of the Z axis labels to 'd' to show them in units of days.
Technically I didn't need to get the axes handle ax, but this ensures that if there are multiple axes open (potentially in multiple figures) I'm changing the format for the correct axes.
ztickformat(ax, 'd')
  1 个评论
johndoe
johndoe 2020-4-12
Thanks for the answer. :) It seems I made a pretty bad job explaining what I was wondering about, sorry. I tried to explain it better to dpb above. Can this be used to plot as time in chart with time, depth and salinity?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by