Matlab箱图属性 [英] Matlab boxplot properties
本文介绍了Matlab箱图属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试绘制这种箱形图,如下所示:
I'm trying to plot this box plot like this:
我尝试了以下代码:
boxplot(randn(10,98)','notch','on')
set(0,'DefaultAxesFontName', 'Cambria Math')
ylabel('Normalized Parameter');
set(gca,'FontSize',14,'fontWeight','bold');
set(gca,'TickLabelInterpreter','tex');
set(gca,'XTickLabel',{'a_{0}','a_{1}','a_{2}','a_{3}','a_{4}','b_{1}','b_{2}','b_{3}','b_{4}','w'})
color = 'b';
h = findobj(gca,'Tag','Box');
for j=1:length(h)
patch(get(h(j),'XData'),get(h(j),'YData'),color,'FaceAlpha',1);
end
lines = findobj(gcf, 'type', 'line', 'Tag', 'Median');
set(lines,'linewidth',1, 'Color', 'r');
如何更改边缘和中线的颜色?
How can i change the edges and median line color?
推荐答案
以下是该代码的固定代码:
Here is a fixed code for that:
g = {'a_{0}','a_{1}','a_{2}','a_{3}','a_{4}','b_{1}','b_{2}','b_{3}','b_{4}','w'};
bx = boxplot(randn(10,98).',g,'notch','on')
ax = gca;
set(0,'DefaultAxesFontName', 'Cambria Math')
ylabel('Normalized Parameter');
set(ax,{'FontSize','FontWeight','TickLabelInterpreter'},{14,'bold','tex'});
h = get(bx(5,:),{'XData','YData'});
for k=1:size(h,1)
patch(h{k,1},h{k,2},[0.4 0.8 0.85]);
end
ax.Children = ax.Children([end 1:end-1]);
主要错误是您将补丁放置在盒子上方,所以最后一行正在修复它.
The main mistake was that you place the patch above the boxes, so the last line is fixing that.
这篇关于Matlab箱图属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文