フィルターのクリア

Is there a way to change the format of a datetime object that affects its display when plotting?

1 回表示 (過去 30 日間)
Matt
Matt 2019 年 10 月 10 日
回答済み: Walter Roberson 2019 年 10 月 10 日
The default Format for a datetime object is:
'dd-MMM-uuuu HH:mm:ss'
If I modify the format to include the time zone, Format becomes:
'dd-MMM-uuuu HH:mm:ss z'
However, when I create a plot with the datetime object, the format of the tick labels does not change. It appears the "Format" property is not used when plotting. Is this true? If so, is there any way to set the format of the datetime object so it will be displayed that way whenever it is plotted? You can use 'xtickformat' after you create the plot, but you have to do that every time you create a plot. Also, this adds the time zone to every tick label, which isn't ideal. It would make more sense if MATLAB handled that in a similar manner to the way it handles the year by default when you plot a datetime object; the year is displayed once, under the rightmost tick label. Is there any way to do this, without resorting to some manual creation of a label on the plot?

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 10 月 10 日
No, you would have to set the individual tick labels.
plot() can only set object properties, so it cannot enact any behaviour that is not supported by an axes property. The only potentially relevant properties are TickLabelFormat and the hidden property DataFormat. DataFormat appears to be a copy of the Format of the first datetime object used on the axes; I have not figured out what it is used for yet.

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by