필터 지우기
필터 지우기

How to increase xticks to axis

조회 수: 2 (최근 30일)
Orongo
Orongo 2019년 5월 14일
편집: Orongo 2019년 5월 14일
Hi, I have tried different solutions online but nothing works. I have a row vector of dimension (1x19) where each value is for years 1995 to 2013. With below script, I get ticks for every other year, but I want it for each year. How can I do this?
y_data=rand(1,19);
x = linspace(1995,2013,19);
plot(x,y_data)
xticks(1995:1:2013);
xticklabels({'1995' '1996' '1997' '1998' '1999' '2000' '2001' '2002' '2003' '2004' '2005' '2006' '2007' '2008' '2009' '2010' '2011' '2012' '2013'})
xlim([1995 2013]);

채택된 답변

Adam Danz
Adam Danz 2019년 5월 14일
편집: Adam Danz 2019년 5월 14일
Your code should already by providing annual ticks. Nevertheless, here are some improvements.
y_data=rand(1,19);
x = 1995:1:2013;
plot(x,y_data)
xticks(x);
% xticklabels({'1995' '1996' '1997' '1998' '1999' '2000' '2001' '2002' '2003' '2004' '2005' '2006' '2007' '2008' '2009' '2010' '2011' '2012' '2013'})
% Remove the line above!
xlim(x([1,end]));
Alternatively, you could use a datetime axis by replacing 1 line above.
% Replace this
x = 1995:1:2013;
% with this
x = years(1995:1:2013);
  댓글 수: 1
Orongo
Orongo 2019년 5월 14일
편집: Orongo 2019년 5월 14일
Works brilliant! Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by