在Matlab的箱图中填色箱中的框 [英] Colorfill the boxes in a boxplot in Matlab
问题描述
有没有一种方法可以在Matlab的箱图中填充箱?
Is there a way to fill the boxes in a boxplot in Matlab?
I was able to change the color of the boundaries of the boxes using the colorgroup
option of the boxplot
function (http://www.mathworks.com/help/stats/boxplot.html), but could not find any option to change the or fill the color of the space inside box itself.
因此,我在链接( http://www.mathworks.com/matlabcentral/newsreader/view_thread/300245 )在评论中指出了user1929959.但是,我是Matlab的新手,我非常希望对代码的功能做一个简短的解释.这是该链接中的代码:
So, I went through the code at the link (http://www.mathworks.com/matlabcentral/newsreader/view_thread/300245) pointed out user1929959 in the comments. However, i am new to Matlab and I would really appreciate a brief explanation of what the code does. Here is the code from that 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.
推荐答案
使用 FINDOBJ 函数,您将在当前轴中搜索标记等于"Box"的图形对象(gca =获取当前轴手柄).
With FINDOBJ function you search for graphic objects with tag equals to 'Box' in the current axes (gca = get current axis handle).
箱形图中所有对象的标记,您可以在官方的MW文档中找到这些标记(仅在示例之前): http://www.mathworks.com/help/stats/boxplot.html
Tags for all objects in boxplot you can find in the official MW documentation (just before examples): http://www.mathworks.com/help/stats/boxplot.html
FINDOBJ将找到的所有对象的句柄返回到变量h(双精度数组)中.您可以使用句柄来修改对象属性.您可以使用get(h(1))
或inspect(h(1))
查看给定句柄的所有属性.
FINDOBJ returns handles to all objects it found into variable h, which is double array. You use the handle to modify the object properties. You can see all properties for a given handle with get(h(1))
or inspect(h(1))
.
例如,您可以设置线宽:
For example you can set line width:
set(h,'LineWidth',3)
由于框是线对象,因此它不具有像补丁一样的FaceColor
或FaceAlpha
(透明度)属性,因此您无法直接对其进行着色.您必须在其上绘制黄色(由"y"参数设置)和0.5透明度的色块.您获得XData
和YData
属性以获取面片坐标.有关所有修补程序属性,请参见此处.
Since box is a line object it doesn't have FaceColor
or FaceAlpha
(transparancy) properties as for patch, so you cannot color it directly. You have to draw patches over it with yellow color (set by 'y' parameter) and 0.5 transparancy. You get XData
and YData
properties to get the patch coordinates. See here for all patch properties.
如果您不知道某些功能的作用,请始终使用help function_name
或doc function_name
查看matlab文档.
Again if you don't know what some function does, always check matlab documentation with help function_name
or doc function_name
.
这篇关于在Matlab的箱图中填色箱中的框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!