Can you convert DatetimeRuler to DurationRuler?

4 次查看(过去 30 天)
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.

采纳的回答

dpb
dpb 2024-7-27
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 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by