Can you convert DatetimeRuler to DurationRuler?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Rohan Kadambi
el 27 de Jul. de 2024
Respondida: dpb
el 27 de Jul. de 2024
I have a series of utilities that generate figures like:
fh = figure;
ax = axes(fh);
plot(ax, datetime("now")+minutes(1:5), 1:5, "--x");
Which use datetime objects for the XData (and therefore have a DatetimeRuler for the x-axis) because it makes it easier to find reference data in the future.
However, for presentations, I generally want plots that use a DurationRuler for the sake of clarity. Is there any way to update ax.XAxis (or maybe even all of the ax.Children entries) such that I could have figures that look like they were generated like this instead:
fh = figure;
ax = axes(fh);
plot(ax, minutes(1:5), 1:5, "--x");
I could update all the plotting utilities to optionally use Duration objects from some reference but this would effect several utilities and it would be more convenient to just pass an axis or figure handle to some function that could do the conversion after the figure exists.
0 comentarios
Respuesta aceptada
dpb
el 27 de Jul. de 2024
Unfortunately, something like
xl=ax.XLim; % retrieve current limits
xl(1)=dateshift(xl(1),"start",'minute'); % round down for first
xl(2)=dateshift(xl(2),"end",'hour'); % up for second
xl1=xl-xl(1) % convert to duration extent
ax.XLim=xl1; % redefine axes as duration
doesn't work; I've submitted enhancement request for the feature previously but so far, no joy.
I have found no way to force one into becoming the other; one has to redraw the graphic to make the change.
Probably the most direct way in your case would be to write a translation routine that does something like the above from the existing figure and then redraws it rather than fixing all the pieces individually, at least as a start.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!