Problem getting number of ticks and labels to work properly

조회 수: 2 (최근 30일)
Thomas Burbey
Thomas Burbey 2019년 10월 25일
댓글: Thomas Burbey 2019년 10월 25일
My x axis corresponds to dates. My data go from Nov 1994 to Dec 2007 and currently the default plots even years from 1996 to 2006. I would like to plot every year from 1995 to 2007. Here's the section of code
xlabel('Year');
xticks = ([daten(47),daten(409),daten(759),daten(1122),daten(1487),daten(1852),daten(2218),daten(2576),daten(2941),daten(3306),daten(3672),daten(4037),daten(4402)]);
xticklabels = ({'1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007'});
xtickangle(45);
daten is a vector of daily values expressed as datetime. The numeric values provided represent the index corresponding to Jan 1 for each year.
I don't get an error yet my x axis plots 1996, 1998, 2000, 2002, 2004, and 2006. I have no idea why it appears to be ignoring my efforts to plot every year.

답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2019년 10월 25일
Do you get your xticks at the even years with the xticklabels for the first 6 years?
You can at least check the x-tick values with
get(gca,'xtick')
In my experience it works well as long as I've have a large enough number of xticklabels to do this:
set(gca,'xtick',xticks,'xticklabel',xticklabels)
HTH
  댓글 수: 1
Thomas Burbey
Thomas Burbey 2019년 10월 25일
This doesn't work because there is no "set" method for a datetime class. I'm wondering if the datetime class is screwing this up. Any suggestions?

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

카테고리

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