Control long datetime xtick

2 次查看(过去 30 天)
Hello. I have an array that starts from 2015 to the end of 2020 every 10 minutes. This is my x-axis. When I plot this the x-axis only shows years, but I would like to show every years and months. I attached the m_file. If you guys know how to do this or tell me some tips for controlling the x-axis, I would be really thankful.

采纳的回答

Walter Roberson
Walter Roberson 2021-4-17
编辑:Walter Roberson 2021-4-17
basedate = datetime(2015,1,1,0,0,0, 'Format', 'yy/MM');
enddate = datetime(2020,12,31,23,59,59, 'Format', 'yy/MM');
wanted_ticks = basedate + calmonths(0:(2020-2015+1)*12)
wanted_ticks = 1×73 datetime array
15/01 15/02 15/03 15/04 15/05 15/06 15/07 15/08 15/09 15/10 15/11 15/12 16/01 16/02 16/03 16/04 16/05 16/06 16/07 16/08 16/09 16/10 16/11 16/12 17/01 17/02 17/03 17/04 17/05 17/06 17/07 17/08 17/09 17/10 17/11 17/12 18/01 18/02 18/03 18/04 18/05 18/06 18/07 18/08 18/09 18/10 18/11 18/12 19/01 19/02 19/03 19/04 19/05 19/06 19/07 19/08 19/09 19/10 19/11 19/12 20/01 20/02 20/03 20/04 20/05 20/06 20/07 20/08 20/09 20/10 20/11 20/12 21/01
sample_dates = linspace(basedate, enddate, 30);
plot(sample_dates, rand(size(sample_dates)))
xticks(wanted_ticks)
  1 个评论
Day Hong Kim
Day Hong Kim 2021-4-18
Thank you for the code. I will study the code and apply into my script. Have a great day!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by