How do I change datetime format in stackedplot on X-Axis?
Mostrar comentarios más antiguos
Right now by default it's in 'hh:mm' I want it to be in 'hh:mm:ss' format with 1 minute interval.
Note: The image shown below is a "stackedplot" and not "plot".

Respuestas (2)
In case anyone is still looking for this solution,
% Create stacked plot, set xdata as datetime values
% The XData can also be set using 'XVariable' for tables but needs to be datetime format.
sph = stackedplot(rand(50,5),'XData',datetime(2020,1,1)+minutes(linspace(0,480,50)));
% Get axis handles
ax = findobj(sph.NodeChildren, 'Type','Axes');
% Set datetime format. The first axis will be the bottom one.
xtickformat(ax(1),'HH:mm:ss')
dpb
el 14 de Jun. de 2019
hAx=gca;
hAx.TickLabelFormat='hh:mm:ss';
You can set the XTick values as wanted but there will not possibly be room to label more than half-hour frequency if that when you add the other text--just not enough real estate to have that much text in such close proximity.
5 comentarios
Vraj Mistry
el 14 de Jun. de 2019
dpb
el 14 de Jun. de 2019
My R2018b got trashed by a windows update and haven't gotten restored so was presuming there'd be duration or timeruler axis underneath.
From the online doc, looks like they've (again) hidden properties -- you can try the FileExchange https://www.mathworks.com/matlabcentral/fileexchange/32934-getundoc-get-undocumented-object-properties routine from Yair and see if you can go "handle diving" to find properties of interest to let you do what you're looking for. Bound to be there somewhere; it's just uncovering how they're buried and whether the object is or is not totally opaque to the user by TMW's design/implementation.
Vraj Mistry
el 14 de Jun. de 2019
getundoc(sp)
ans =
struct with fields:
ApplicationData: [1×1 struct]
Axes: [1×1 Axes]
MaxNumAxes: 25
MaxVarIndex: 1
MessageHandle: [1×1 TextBox]
MinAxesHeight: 20
NodeChildren: [2×1 Graphics]
NodeParent: [1×1 ScribeLayer]
NumPlotsInAxes: 5
...
Plots: {[1×5 Line]}
Selected: 'off'
...
Behavior: [1×1 struct]
Well, there's an Axes handle to start probing... don't give up so quickly!!
dpb
el 15 de Jun. de 2019
Also, try setting the display format for the x-axis variable before plotting -- possibly the function will look at that in deciding the display format.
Categorías
Más información sobre Annotations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
