带错误条的小组图

时间:2017-11-01 10:58:41

标签: matlab plot matlab-figure legend errorbar

我有以下代码制作情节:

dfs = [0  5 10 15 20 25 ];
Intensities = [0.0593 0.0910 0.1115 0.0611 0.0975 0.0715] ;
SE = [0.2165 0.2068 0.2555 0.2479 0.2340 0.2239];

errorbar(dfs, Intensities, SE, 'ro');
hold on
plot(dfs,Intensities,'bo');
title('\fontsize{14}Intensities per condition');
hold off;

ylim([-0.2 0.5])

names = {'\fontsize{12}Cond1, Group1'; '\fontsize{12}Cond2, Group1'; '\fontsize{12}Cond1, Group2'; '\fontsize{12}Cond2, Group2'; '\fontsize{12}Cond1, Group3';'\fontsize{12}Cond2, Group3'};
set(gca, 'xtick', dfs, 'xticklabel', names);
xlim([-1 26]);  %just for better visualisation
ylabel('\fontsize{14}Intensities')

我想用成对的误差条对点进行分组。所以点(点估计)1, 3, and 5都属于条件1,而点2, 4 and 6属于条件2.我的意思是应该有一些指示1, 3, 5属于条件1和2, 4, 6条件2,例如传说。但是legend('Condition 1','Condition 2')在这里无效。将所有信息放在xaxis ticks上的内容太多了。或者,也可以明确前两个属于group1,接下来两个属于group2等 可以做些什么?

1 个答案:

答案 0 :(得分:2)

为区分,请更改点的颜色并在图例中提及它们。 对于您的情况,如果有一些条件和许多组,最好使用图例中的条件(这是您首先声明的所需结果)。但是,如果有一些组和许多条件,最好在图例中使用组(您作为替代方案编写)。

对于第一种情况,即少数条件和许多组,请将plot命令替换为:

h(1) = scatter(dfs(1:2:end),Intensities(1:2:end),'o','filled');
h(2) = scatter(dfs(2:2:end),Intensities(2:2:end),'o','filled');
%filling the dots so that your eyes may not dodge you about the colors :D
%I choose 1:2:end and 2:2:end for the first and second lines since there seems to be
%an order. If there is no order, you can explicitly state that as: [1 3 5] or [2 4 6]

然后删除您更改xticklabels的行并将图例用作:

legend(h,'condition1','condition2');

output1
图1:较少的条件,许多组

对于第二种情况,即少数组和许多条件,请将plot命令替换为:

for k=1:3
    h(k) = scatter(dfs([2*k-1 2*k]),Intensities([2*k-1 2*k]),'o','filled'); 
end                    %     ^---------generalised the formula

然后删除更改xticklabels的行并将图例用作:

legend(h,'group1','group2','group3');

output2
图2:更多条件,更少的群体