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.
Thanks, that's a smart way. You can avoid the loop by writing
ReplyDeleteset(hl(1:6,:),'LineWidth',2);
Indeed a smart way
ReplyDeleteThanks man! rightaway what i was looking for! keep posting!
ReplyDeleteThanks for the post! I only don't understand why the function is boxplot(X,G,'color',...) and not 'colors'? There is nothing in the manual about 'color'. Has it changed, because I'm using 2010a?
ReplyDeleteMaybe offtopic, but I found that if you put a nx3 matrix Mrgb e.g.
[0.5 0.5 0.5;
1 1 1;
0 1 0] etc. when you use boxplot(X,G,'colors',Mrgb) you essentially get a third dimension in your boxplot. So, it's like a pseudo 3D boxplot.
It turned out really useful for me when I had X values of different lengths (see here for solution: http://www.mathworks.com/support/solutions/en/data/1-7SP1DM/index.html?product=ML)
Thank you! That is exactly what I am looking for :)
ReplyDeleteMATLAB helps are suck.
ReplyDeleteI agree. Thank a lot for your post
May be it was too complicated for describing the handls of the function and the relationship about gca & gcf.
DeleteThanks! Very helpful and impossible to find elsewhere. Why is ih cycled through 1:6 in the for loop?
ReplyDeletearticle that you created is very interesting, by reading this article I have a reference to write a new post on my blog
ReplyDeletethis routine loses the 'whisker' value, and resets it to the default 1.5
ReplyDeletethank you!
ReplyDeleteThat's exactly what I was looking for. However, I need to do the same in Octave.
ReplyDeleteAny thoughts? Thnx.