How do I change the timezone of the X axis on an existing plot?

8 ビュー (過去 30 日間)
Andrew Liu
Andrew Liu 2018 年 10 月 1 日
編集済み: Benjamin Kraus 2023 年 3 月 17 日

Suppose I have a figure with one or more line objects, e.g.

T = datetime(2018,1,1,0,0,0,'TimeZone','UTC')+minutes([0:9]);
y1 = 1:10;
y2 = 10:-1:1;
figure; 
plot(T,y1); 
hold all; 
plot(T,y2);

Now I want the X axis to display in a different timezone, e.g. 'Asia/Taipei'. I've tried modifying the x limits, the x tick values, the properties in the date-time ruler, the individual XData in the line objects, and making changes after turning off visibility of the XAxis and Line objects. Each time I change the time zone in one of these object properties, the zone is automatically reverted to UTC. Is there anything I can do short of copying the data out of my original figure and re-plotting new data in an updated time-zone?

  1 件のコメント
dpb
dpb 2018 年 10 月 1 日
編集済み: dpb 2018 年 10 月 1 日
I confirm the behavior here (R2017b); looks like a bug to me; seems as though the axis ought to reflect the date/time including timezone of the underlying data, agreed.
I'd report it as a bug; see the "contact us" link at top of page or email <mailto:support@tmw.com support@tmw.com>; attach link to the Q? here.

サインインしてコメントする。

採用された回答

Benjamin Kraus
Benjamin Kraus 2023 年 3 月 17 日
編集済み: Benjamin Kraus 2023 年 3 月 17 日
Starting in MATLAB R2023a, you can now update the time zone of the x-axis on existing plots by setting the ReferenceDate on the ruler.
You can read about this on the DatetimeRuler Properties doc page.
T = datetime(2018,1,1,0,0,0,'TimeZone','UTC')+minutes([0:9]);
y1 = 1:10;
y2 = 10:-1:1;
figure;
plot(T,y1);
hold all;
plot(T,y2);
ax = gca;
ax.XAxis.ReferenceDate = datetime(2018,1,1,0,0,0,'TimeZone','Asia/Taipei');

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by