Showing posts with label How to?. Show all posts
Showing posts with label How to?. Show all posts

Tuesday, April 7, 2009

Matlab boxplot: how to change the line width (LineWidth) and color of the lines?

It was hard for me to find the solution of this problem using Matlab help. Finally I found the solution and writing here so that it can be useful for you.

The following example creates four plots. Simple copy and paste the whole code and see what it does.

---
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


This example creates a plot which looks like; you can choose the option which fits you.