Plotting time/date on surf or mesh plot
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
dpb
le 12 Avr 2020
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.
Réponse acceptée
Steven Lord
le 11 Avr 2020
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')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots 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!
