Datenum axes scaling.

조회 수: 4 (최근 30일)
Antony
Antony 2011년 11월 10일
Hello, everyone!
I'm writing a GUI containing axes with datestr vector as X data, and it creates a plot with 3 months long ticks. Now, I want to scale it from start_date_num to end_date_num, and, for example, switch my datetick to 1 year if time period is more than 2 years. The problem is that I can't create the new XTick vector that would point exactly on the 1st of January of every year (depends on 365/366 days a year, and on lesser scales - on 28/29Feb, 30/31days a month). The code I tried:
time_period = scale_end - scale_start;
set(axes_handle, 'XTickMode', 'auto');
if time_period > (365*2)
datetick(axes_handle, 'x', 'yy');
set(get(axes_handle, 'XLabel'), 'String', 'Time (year)');
end
set(axes_handle, 'XLim', [start_date_num end_date_num]);
This showed the right picture with Xlabels changed to the needed ones, but still 3 months away from each other.
Any help is appreciated, thank in advance!

채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 10일
Set explicit XTick yourself instead using automatic mode. It usually isn't fun to figure out "nice" ticks as the user zooms and pans arbitrarily, but it can be done.
  댓글 수: 1
Antony
Antony 2011년 11월 11일
"It usually isn't fun to figure out "nice" ticks as the user zooms and pans arbitrarily, but it can be done."
Thank you for the answer, but that's what I meant by "The problem is that I can't create the new XTick vector that would point exactly on the 1st of January of every year (depends on 365/366 days a year, and on lesser scales - on 28/29Feb, 30/31days a month)."
Problem solved by replotting all lines cut, though this solution is not very elegant and needed certain shamanism.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by