Plot data with x-axis as date

3 ビュー (過去 30 日間)
Monsef Tahir
Monsef Tahir 2019 年 2 月 13 日
コメント済み: Abby Skofield 2023 年 9 月 20 日
Hello Community,
I have a vector of data (1x3040) representing time series data of one year measured each 15 min. I need to use a subplot function to the plot the data and show the Month's names only on x-axis like : Jan July Dec. On the second plot ( vector data (1x288) ), I need to show x-axis as Jan-1 Jan-2 Jan-3.
Any suggestions ?
  2 件のコメント
TADA
TADA 2019 年 2 月 13 日
can you share a small example of the data?
Monsef Tahir
Monsef Tahir 2019 年 2 月 14 日
It is like x=[ 0 0 0 0.1 0.12 0.2 0.3 0.2 0.1 0.09 0]; this is just anexample of 35040 points

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

採用された回答

dpb
dpb 2019 年 2 月 13 日
編集済み: dpb 2019 年 2 月 14 日
t=datetime(2019,1,1,0,0:15:365*24*60-15,0);
plot(t,randn(size(t)))
hAx=gca;
hAx.XTick=datetime(2019,[1 7 12],1);
ADDENDUM:
xtk=hAx.XTick;
xtk.Format='MMM';
hAx.XTickLabel=cellstr(xtk.');
ADDENDUM SECOND:
NB: Unfortunately, internals for the datetime axis object silently adds a year back in if one tries
hAx.XTick=datetime(2019,[1 7 12],1);
xtk=hAx.XTick;
xtk.Format='MMM';
hAx.XTick=xtk;
the use of the TickLabel property with the formatted date is the only way I've found that works to override the behavior.
One would think like on the numeric ruler there would be a way to indicate if wanted the explicit year shown or not, but no! TMW didn't think we needed that nicety. There's not even a hidden property that could use. :(
Worthy of an enhancement request/quality-of-implemenation topic. I don't recall if I submitted this one the when this came up; first I recall within a few months back...but I couldn't find the particular thread to link to.
  2 件のコメント
Monsef Tahir
Monsef Tahir 2019 年 2 月 13 日
編集済み: Monsef Tahir 2019 年 2 月 14 日
Works great thank you. Is there anyway to remove the year from x-axis and keep the months only.
Abby Skofield
Abby Skofield 2023 年 9 月 20 日
@Monsef Tahir Starting in MATLAB R2023b, you can add, remove, or update the secondary labels using the new functions xsecondarylabel, ysecondarylabel, zsecondarylabel.
t=datetime(2019,1,1,0,0:15:365*24*60-15,0);
plot(t,randn(size(t)))
hAx=gca;
hAx.XTick=datetime(2019,[1 7 12],1);
xsecondarylabel(Visible='off')

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by