Plotting time/date on surf or mesh plot

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 Commenti

Need show us what you did, attach .jpg of result and what you think isn't what you would like...attaching the data would let somebody have an opportunity on own to try as well. W/o additional info, not much we can do--we can't see your terminal from here.
Yeah, when I read it again, I realized i could have done a much better job explaining. I basically got 3 colums with salinity, depth and the time of measurement. Posting part of a chart, with time along the X-axis, depth along y-axis and salinity in shifting colors. In the chart I've used YYMMDD format and years 1960, 1965 and 1970 shows as 1.96, 1.965 and 1.97. This is what I would like to change, to have it in years instead.
When i tried it in YYYY format there would be a alot of the measurements that got averaged out becuase they where made in the same year, and this I don't want happening. Not fore measurements done in the same month either, same day would be ok if it got averaged out i guess.
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.
That helped, thanks!

Accedi per commentare.

 Risposta accettata

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 Commento

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?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by