Question about labels under each boxplot.

45 ビュー (過去 30 日間)
Marcus Vinicius Pereira de Souza
Marcus Vinicius Pereira de Souza 2012 年 2 月 26 日
回答済み: Ankita 2023 年 2 月 8 日
Dear all, I need to put labels under each boxplot. To do this, I'm using: boxplot([dados(:,1),dados(:,2)],'labels',{'bf\it{IDEB}_2_0_0_7'},{'\bfEfficiencies'}) Unfortunately, I don´t have sucess. Can someone help me? Best regards. Marcus Vinicius

回答 (7 件)

Jiro Doke
Jiro Doke 2012 年 2 月 26 日
When you say you don't have success, I assume you're saying that the labels aren't being rendered with the bold/italics/subscript formatting.
Try this:
dados = rand(100,2);
boxplot(dados,'labels',{'\bf\it{IDEB}_2_0_0_7','\bf Efficiencies'})
h = findobj(gca, 'type', 'text');
set(h, 'Interpreter', 'tex');
  1 件のコメント
Tom Cook
Tom Cook 2019 年 4 月 21 日
Hi, I kinda have the same problem. And your solution jiro does not work for me (MATLAB R2017a)!
Why? How can I make it work?
Why is there no proper handle for the boxplot function like for any other plot function?!

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


Oleg Komarov
Oleg Komarov 2012 年 2 月 26 日
dados = rand(100,2)
boxplot(dados,'labels',{'\bf\it{IDEB}_2_0_0_7','\bf Efficiencies'})

Marcus Vinicius Pereira de Souza
Marcus Vinicius Pereira de Souza 2012 年 2 月 26 日
Dear Oleg, Thanks you very much for your attention. But, unfortunately, the labels aren't being rendered with the bold/italics/subscript formatting. Best wishes, Marcus Vinicius

Marcus Vinicius Pereira de Souza
Marcus Vinicius Pereira de Souza 2012 年 2 月 26 日
Dear Jiro, Thanks you very much for your attention. How do I do so that the name IDEB_2007 does not sit so close to the x-axis? Best wishes, Marcus Vinicius

Chathurika
Chathurika 2013 年 8 月 29 日
set boxplot labels bold and font size of 16...
boxplot(X,'labels',{'a','b','c'})
set(findobj(gca,'Type','text'),'FontSize',16,'fontweight','bold')

Tyler
Tyler 2015 年 2 月 26 日
This page helped solve my issues using boxplots. I will list out all the tweaks I wanted done to my boxplot in case it helps anyone else.
I found all the editable properties using:
get(gca)
h = findobj(gca, 'type', 'text');
get(h(1))
and so on.
Here is an example of my tweaks:
data = rand(100,1); %random data
% a label for each data point
labels = repmat({'group2','group3','group1','group3'}',25,1);
Label_size = 15;
%used grouporder to arange the order of the boxes
%the labels option let you rename the labels (from group1 to G1)
boxplot(data,labels,'grouporder',{'group1','group2','group3'},'label',{'G1','G2','G3'})
xlabel('Labels','FontSize',Label_size,'FontWeight','bold')
ylabel('Data','FontSize',Label_size,'FontWeight','bold')
title('Nice Boxplot','FontSize',Label_size,'FontWeight','bold')
h = findobj(gca, 'type', 'text');
% this alters Yticklabels [0 to 1]
set(gca,'FontSize',Label_size);
set(gca,'FontWeight','bold')
% this alters the group labels: G1, G2, G3
set(h,'FontSize',Label_size);
set(h,'Interpreter','tex');
set(h,'FontWeight','bold')
% this moves the groups labels and the Xlabel down to avoid overlap
for j=1:length(h)
set(h(j),'Position',get(h(j),'Position')+[0 -5 0]);
end
h2 = get(gca, 'XLabel');
set(h2,'Position',get(h2,'Position')+[0 -8 0]);
You can change almost anything about any of the text this way, just look up the text properties you want to change, for more information see: text-properties.

Ankita
Ankita 2023 年 2 月 8 日
data = rand(100,1); %random data
% a label for each data point
labels = repmat({'group2','group3','group1','group3'}',25,1);
Label_size = 15;
%used grouporder to arange the order of the boxes
%the labels option let you rename the labels (from group1 to G1)
boxplot(data,labels,'grouporder',{'group1','group2','group3'},'label',{'G1','G2','G3'})
xlabel('Labels','FontSize',Label_size,'FontWeight','bold')
ylabel('Data','FontSize',Label_size,'FontWeight','bold')
title('Nice Boxplot','FontSize',Label_size,'FontWeight','bold')
h = findobj(gca, 'type', 'text');
% this alters Yticklabels [0 to 1]
set(gca,'FontSize',Label_size);
set(gca,'FontWeight','bold')
% this alters the group labels: G1, G2, G3
set(h,'FontSize',Label_size);
set(h,'Interpreter','tex');
set(h,'FontWeight','bold')
% this moves the groups labels and the Xlabel down to avoid overlap
for j=1:length(h)
set(h(j),'Position',get(h(j),'Position')+[0 -5 0]);
end
h2 = get(gca, 'XLabel');
set(h2,'Position',get(h2,'Position')+[0 -8 0]);

カテゴリ

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