用Matlab实现条形图中的阴影条和标准差误差
我正在尝试创建一个条形图。在x轴上,我有4种不同的条件:HFd,HFi,LFd,LFi。在y轴上显示反应时间 我需要代表HFd的条带阴影和蓝色,HFi为蓝色,LFd为阴影和红色,LFi为红色。此外,我需要在每个条上以黑色显示标准偏差。 以下是我的尝试。虽然他们工作,但他们没有给我需要的条形图。任何帮助都将不胜感激用Matlab实现条形图中的阴影条和标准差误差,matlab,bar-chart,Matlab,Bar Chart,我正在尝试创建一个条形图。在x轴上,我有4种不同的条件:HFd,HFi,LFd,LFi。在y轴上显示反应时间 我需要代表HFd的条带阴影和蓝色,HFi为蓝色,LFd为阴影和红色,LFi为红色。此外,我需要在每个条上以黑色显示标准偏差。 以下是我的尝试。虽然他们工作,但他们没有给我需要的条形图。任何帮助都将不胜感激 %% This code creates the plot, but without the standard deviation errors and the different c
%% This code creates the plot, but without the standard deviation errors
and the different colours.
data1 = [228, 222, 229, 218];
sdev1 = [29, 30, 29, 31];
hold on;
figure;
bar(data1);
%errorbar(data1, sdev1); %it gives me a line that links the different standard deviation errors.
set(gca, 'XTickLabel',{'HFd', 'HFi', 'LFd', 'LFi'});
ylabel('Reaction time (ms)');
ylim([180 300]);
%% This code creates the plot, with different colours but without the hatched
patterns and the standard deviation errors.
dataHFdeg = [228, 0, 0, 0];
sdev11 = [29, 0, 0, 0]
dataHFid = [0, 222, 0, 0];
sdev12 = [0, 30, 0, 0]
dataLFdeg = [0, 0, 229, 0];
sdev13 = [0, 0, 29, 0]
dataLFid = [0, 0, 0, 218];
sdev14 = [0, 0, 0, 31]
bar(dataHFd,'b');
set(gca, 'XTickLabel',{'HFd', 'HFi', 'LFd', 'LFi'});
ylabel('Reaction time (ms)');
ylim([180 300]);
hold on;
bar(dataHFi, 'b');
hold on;
bar(dataLFd, 'r');
hold on;
bar(dataLFi, 'r');
更新:
%%此代码创建具有不同颜色和错误条的绘图,但没有阴影图案
y = [228; 222; 229;218]; %The data.
s = [29;30;29;31]; %The standard deviation.
fHand = figure;
aHand = axes('parent', fHand);
hold(aHand, 'on')
bar(1, y(1), 'parent', aHand, 'facecolor', 'b');
bar(2, y(2), 'parent', aHand, 'facecolor', 'b');
bar(3, y(3), 'parent', aHand, 'facecolor', 'r');
bar(4, y(4), 'parent', aHand, 'facecolor', 'r');
colors = copper(numel(y) - 4);
for i = 5:numel(y)
bar(i, y(i), 'parent', aHand, 'facecolor', colors(i-4,:));
end
set(gca, 'XTick', 1:numel(y), 'XTickLabel', {'HFd','HFi','LFd','LFi'})
ylim([180 300]);
errorbar(y,s,'.');
%%例如,为第二个条创建阴影图案-但它不起作用
applyhatch_pluscolor(bar(2,y(2)), '/', 1);
MATLAB没有现成的函数来创建阴影条。幸运的是,您可以在文件交换中找到一些解决方案:@Amro,我已尝试跟踪您的链接。但是,我仍然无法创建阴影条。我已经更新了我的问题,以便看到新的尝试。如果有人能帮忙,我将非常感激。