フィルターのクリア

how to adjust graph labels ?

2 ビュー (過去 30 日間)
Amr Hashem
Amr Hashem 2015 年 7 月 28 日
編集済み: dpb 2015 年 7 月 29 日
I use this code to label the graph:
[ndata2 text2 alldata2] = xlsread('all.xlsx','wordsort50');
a=alldata2;
figure('color','w')
bar(cell2mat(a(:,2)));
set(gca,'XTick',1:size(a,1))
set(gca,'XTickLabel',a(:,1))
xticklabel_rotate([],90,a(:,1));
set(gca,'YTick',0:1000:max(cell2mat(a(:,2))))
but i want y tick to be (0,1000,2000,3000,...21000) not (0.1,0.2...) how i can do this ? and how to fit the x label along the x-axis?

回答 (1 件)

dpb
dpb 2015 年 7 月 28 日
編集済み: dpb 2015 年 7 月 29 日
yt=[0:1000:max(cell2mat(a(:,2)))].';
set(gca,'YTick',yt,'yticklabel',num2str(yt,'%d'))
What does "how to fit the x label along the x-axis?" mean, precisely?
"spread the x labels along the x axis, without leaving a space at the end"
xlim([1-5/8 50+5/8])
That is, you don't "spread the labels", you adjust the limits to be tighter around the data. This is the mechanism for all plot styles.
I have found the above (subtract/add 0.625 to the first/last bin numbers) to produce a satisfactory appearance in most bar plots I've created.
Adjust the fractions to suit for amount of white space desired; I counted (I think) 50 bars; adjust upper limit to actual.
  1 件のコメント
Amr Hashem
Amr Hashem 2015 年 7 月 29 日
I mean to spread the x labels along the x axis, without leaving a space at the end as it appear in the image.

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

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by