Matlab boxplot properties

僤鯓⒐⒋嵵緔 提交于 2019-12-24 00:39:51

问题


I'm trying to plot this box plot like this:

I tried this code:

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?


回答1:


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.



来源:https://stackoverflow.com/questions/38399688/matlab-boxplot-properties

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!