Bar plot with different label for each bar

5 ビュー (過去 30 日間)
Marko Baros
Marko Baros 2014 年 3 月 24 日
回答済み: Star Strider 2014 年 3 月 24 日
Hello,
I would like to ask someone for help about labeling specific bar with specific name. I've done it, but since the labels couldn't be shorter, I want to know if these labels are able to be rotated or written vertically?
Part of script:
figure
bar([1:22],Qm)
xlabel('Different sequences')
ylabel('Mean qualities')
title('Distribution of mean qualities')
set(gca, 'XTick', 1:22, 'XTickLabel', labels);
%labels is a vector of strings
and this look like this:
but I would like to have it in this way:
or to have labels inside the bars.
Thank you in advance!
Cheers, Marko

回答 (3 件)

dpb
dpb 2014 年 3 月 24 日
Tick labels don't have the facility to be modified other than font characteristics but you can use text to label wherever you wish and use TeX and other features of the text object to orient to your heart's content.
Start with
doc text
and follow the links to the properties available and examples. There's a section w/ such in the Graphics chapter under Annotation that's a good intro...

Marko Baros
Marko Baros 2014 年 3 月 24 日
Hey, I got idea and I just had to switch axes using barh, so I got this:
but the thing is that I would need to sort the bars in ascending or descending way, but not sure how to do it.

Star Strider
Star Strider 2014 年 3 月 24 日
I remember doing this before, but not very recently. The text idea is definitely the solution:
fr = rand(100,1);
[c b] = hist(fr);
for k1 = 1:length(b)
barlbl{k1} = sprintf('Bar # %2d\n', k1);
end
figure(1)
bar(b, c)
set(gca,'XTick',1:length(b))
set(gca,'XTickLabel', text(b,ones(size(b))-1.5, barlbl,'Rotation',45,'FontSize',7, 'HorizontalAlignment','right'))
axis tight
There is no truly automatic way to position labels of varying length, so you’ll have to experiment to get the result you want.

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by