Bar plot with different label for each bar
조회 수: 5 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (3개)
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...
댓글 수: 0
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!