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!