xticklabels function for more than 11 labels ?

Hello everyone ,
I need to use the function "xticklabels" for labeling the x-axis this is my code:
figure (1)
xticklabels({'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'})
but the figure display only till 'nov' how can I include the last one ?
Thank you.

 채택된 답변

Jan
Jan 2018년 7월 10일

1 개 추천

It is smarter to avoid the hard coding to set the names of the months, but to use datetick to display the names dynamically and automatically adjusted to the data.

댓글 수: 4

could you show me please how to do this ?
Jan
Jan 2018년 7월 10일
편집: Jan 2018년 7월 10일
I'd start with doc datetick (link) .
Please read this at first. If a detail is not clear, ask specifically.
This example might be useful:
startDate = datenum('01-01-2009');
endDate = datenum('12-31-2009');
xData = linspace(startDate,endDate,12);
ax = axes;
bar(xData,rand(1,12))
ax.XTick = xData;
datetick(ax1,'x','mm','keepticks')
pause(1)
datetick(ax1,'x','mmm','keepticks')
Reema Alhassan
Reema Alhassan 2018년 7월 10일
편집: Reema Alhassan 2018년 7월 10일
Thank you so much !
Instead of using datetick, consider plotting a datetime array.
startOfYear = dateshift(datetime('today'), 'start', 'year');
randomDays = randi([0 364], 1, 20);
D = startOfYear + days(sort(randomDays));
D.Format = 'MMM dd';
plot(D, 1:20, '-o')

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

추가 답변 (1개)

Mandeep  Singh
Mandeep Singh 2018년 7월 10일

0 개 추천

From my understanding of the problem, you could specify the xticks before xticklabel to get the desired output . Try the following example snippet:
xticks(1:12)
xticklabels({'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'})
The value of the xticks can be varied according to the data you are plotting.

댓글 수: 3

this is what I'm getting ..
jonas
jonas 2018년 7월 10일
편집: jonas 2018년 7월 10일
The problem is that when you create a default figure, then matlab makes an axis with xlim=[0 1] with 11 equally spaced xtick. You can just change the xlim to get your desired results, but for almost any application I would suggest using Jan's method instead.
Thank you so much

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

카테고리

도움말 센터File Exchange에서 Axis Labels에 대해 자세히 알아보기

질문:

2018년 7월 10일

댓글:

2018년 7월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by