How can I set time for x-axis plot in standard year, month,
조회 수: 3 (최근 30일)
이전 댓글 표시
Please find the attached files I want to display time in form of 2017-04, 2017-07, etc. for x-axis. I have trying the following command but is not what I expected, The time reference since 1950-01-01T00: 00: 00Z. eg, 67 + 1950 = 2017
datetick ('x', 'yyyy-mm', 'keeplimits')
댓글 수: 3
답변 (1개)
Peter Perkins
2020년 4월 14일
I have no idea what that mat file is intended to contain. It's one double vector.
In any case, don't use datetick. Just use datetime plotting:
>> t = datetime(2020,1,1:100:1000);
>> y = 1:20;
>> pcolor(t,y,rand(length(y),length(t)))
Normally, you could set the datetime format to what you need, but your case is ... unusual. You'll need to make the tick labels by hand. Get the tick locations, get the offset from 1950 in years and months, and build the labels.
>> ax = gca;
>> t0 = datetime(1950,1,1);
>> ticks = ax.XTick;
>> [y,m] = split(between(t0,ticks),["years","months"])
y =
70 70 71 71 72
m =
0 6 0 6 0
>> xlabs = compose("%04d-%02d",[y',m'])
xlabs =
5×1 string array
"0070-00"
"0070-06"
"0071-00"
"0071-06"
"0072-00"
>> ax.XTickLabel = xlabs;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Polar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!