Color the boxes in the box in Matlab

Is there a way to fill in the fields in a box in Matlab?

I managed to change the color of the borders of the boxes using the colorgroup option of the colorgroup function ( http://www.mathworks.com/help/stats/boxplot.html ), but could not find any way to change or fill the color of the space inside the window itself.

Edit: So, I looked at the code at the link ( http://www.mathworks.com/matlabcentral/newsreader/view_thread/300245 ) pointed to user1929959 in the comments. However, I'm new to Matlab, and I would really appreciate a brief explanation of what the code does. Here is the code from this link:

 load carsmall boxplot(MPG,Origin) h = findobj(gca,'Tag','Box'); for j=1:length(h) patch(get(h(j),'XData'),get(h(j),'YData'),'y','FaceAlpha',.5); end 

I am also open to other solutions. Thanks.

+1
source share
1 answer

With FINDOBJ, you search for graphical objects with a tag equal to "Box" in the current axes (gca = get current axis handle).

You can find tags for all objects in boxplot in the official MW documentation (just before the examples): http://www.mathworks.com/help/stats/boxplot.html

FINDOBJ returns the descriptors of all objects found in the variable h, which is a double array. You use a handle to change the properties of an object. You can see all the properties for a given descriptor using get(h(1)) or inspect(h(1)) .

For example, you can set the line width:

 set(h,'LineWidth',3) 

Since box is an object of the line, it does not have the FaceColor or FaceAlpha (transparency) properties, as for a patch, so you cannot paint it directly. You must apply patches with yellow color (specified by the "y" parameter) and 0.5 transparency. You get the XData and YData to get the coordinates of the patch. See here for all patch features.

Again, if you don’t know what a function is doing, always check the matlab documentation with help function_name or doc function_name .

+2
source

All Articles