Skip to content

Instantly share code, notes, and snippets.

@raviramanathan
Last active September 21, 2021 17:37
Show Gist options
  • Save raviramanathan/9367925 to your computer and use it in GitHub Desktop.
Save raviramanathan/9367925 to your computer and use it in GitHub Desktop.
Controlling boxplots in Matlab
Controlling boxplots in Matlab
The tricky problems I found was
1) in controlling the width of the lines for the outlines of the boxes in the boxplots and
h=boxplot(DATA,Vect)
for ih=1:numRowsOfDATA
set(h(ih,:),'LineWidth',2); % Set the line width of the Box outlines here
end
2) changing the fontsize of the axis labels for X axes!
for example,
box on %would only impact one of the axes - Yaxes !
The work around to increase size of XTicks was:
set(findobj(gca,'Type','text'),'FontSize',12,'fontWeight','bold') % to set Xaxis
set(gca,'FontSize',12,'Fontweight','bold') % to set Yaxis
clear all
close all
a=rand(5)*100
%figure To create default box plot of matlab
subplot 221
h=boxplot(a)
%figure To change the linewidth of the box plot,
subplot 222
hl=boxplot(a)
for ih=1:6
set(hl(ih,:),'LineWidth',2);
end
%figure To change the color of the blox plot, here green is used
subplot 223
hc=boxplot(a,'Color','g')
%figure, To change colour as well as linewidth
subplot 224
hlc=boxplot(a,'Color','r')
for ih=1:6
set(hlc(ih,:),'LineWidth',2);
end
% taken from : http://vikas-ke-funde.blogspot.com.es/2009/04/matlab-boxplot-how-to-change-line-width.html
@ha7ilm
Copy link

ha7ilm commented Sep 21, 2021

Change line width of markers for outliers as well:

hlc=boxplot(...);
for ih=1:7, set(hlc(ih,:),'LineWidth',2); end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment