Is it possible to change label names in Matlab
11 ビュー (過去 30 日間)
古いコメントを表示
I want to have different names in my Y axis rather than numbering like the following photo:
0 件のコメント
採用された回答
Chad Greene
2015 年 6 月 24 日
Here I'll do a barh(A) where A is not sorted, and I'll label the different groups based on the longest bar. Then sort according to the size of the first column in A while preserving the group label association. I adjusted the values in your A a little bit to make it more clear:
A = [2,6,50;3,4,90;1,6,103];
longbar = {'shortest','middle','longest'};
subplot(211)
barh(A)
set(gca,'ytick',1:3,'yticklabel',longbar)
title 'unsorted data:'
box off
% Resize based on first column:
[values, order] = sort(A(:,1));
sortedmatrix = A(order,:)
subplot(212)
barh(sortedmatrix)
set(gca,'ytick',1:3,'yticklabel',longbar(order))
title 'sorted data:'
box off
その他の回答 (3 件)
Sean de Wolski
2015 年 6 月 24 日
Adjust the axes' 'YTickLabel' property:
barh(rand(3,1));
ax = gca;
ax.YTickLabel = {'Hello','World','Wednesday'}
Chad Greene
2015 年 6 月 24 日
plot(1:9,1:9)
set(gca,'ytick',1:9,'yticklabel',{'book','pen','vb','top','red','green','black','green','verb'})
0 件のコメント
Azzi Abdelmalek
2015 年 6 月 24 日
t=0:10;
y=sin(t)
plot(y)
s={'a' 'b' 'c' 'd' 'e' 'f'}
yt=get(gca,'ytick')
n=numel(s)
set(gca,'xtick',linspace(min(yt),max(xt),n),'yticklabel',s')
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!