xticklabels function for more than 11 labels ?

1 回表示 (過去 30 日間)
Reema Alhassan
Reema Alhassan 2018 年 7 月 10 日
コメント済み: Steven Lord 2018 年 7 月 10 日
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 日
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 件のコメント
Reema Alhassan
Reema Alhassan 2018 年 7 月 10 日
編集済み: Reema Alhassan 2018 年 7 月 10 日
Thank you so much !
Steven Lord
Steven Lord 2018 年 7 月 10 日
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 日
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 件のコメント
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.
Reema Alhassan
Reema Alhassan 2018 年 7 月 10 日
Thank you so much

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGrid 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