Can you convert DatetimeRuler to DurationRuler?

2 vues (au cours des 30 derniers jours)
Rohan Kadambi
Rohan Kadambi le 27 Juil 2024
Réponse apportée : dpb le 27 Juil 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.

Réponse acceptée

dpb
dpb le 27 Juil 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.

Plus de réponses (0)

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by