How to plot correctly errorbars on grouped bar plot?
Hello everyone,
I am using a livescript to present some data.. data is a 4×7 matrix, so nbars is 4, ngroups is 7
figure
labels = categorical({‘Mental Demand’ ‘Physical Demand’ ‘Temporal Demand’ ‘Performance’, ‘Effort’, ‘Frustration’, ‘Overall’});
b=bar(labels’,data’);
title(‘RAW NASA TLX’);
box off
hold on
% Calculate the number of groups and number of bars in each group
[ngroups,nbars] = size(data’);
% Get the x coordinate of the bars
x = nan(nbars,ngroups);
for i = 1:nbars
x(i,:) = b(i).XEndPoints;
end
% Plot the errorbars
errorbar(x’,data’,error’,’k’,’linestyle’,’none’);
hold off
legendText = cell(1, numel(A));
for i = 1:numel(A)
cameraType = A{i};
legendText{i} = cameraType;
end
legend(legendText);
The resulting plot in the livescript is wrong: all the errorbars are in the center of each of the respective group
But if I put the same code in the command window the plot is correct
Can you explain me what is going on?
I am sure that I am doing something wrong but I can not understand why (I took the errorbar part from some code online, it seems right to me but idk…)Hello everyone,
I am using a livescript to present some data.. data is a 4×7 matrix, so nbars is 4, ngroups is 7
figure
labels = categorical({‘Mental Demand’ ‘Physical Demand’ ‘Temporal Demand’ ‘Performance’, ‘Effort’, ‘Frustration’, ‘Overall’});
b=bar(labels’,data’);
title(‘RAW NASA TLX’);
box off
hold on
% Calculate the number of groups and number of bars in each group
[ngroups,nbars] = size(data’);
% Get the x coordinate of the bars
x = nan(nbars,ngroups);
for i = 1:nbars
x(i,:) = b(i).XEndPoints;
end
% Plot the errorbars
errorbar(x’,data’,error’,’k’,’linestyle’,’none’);
hold off
legendText = cell(1, numel(A));
for i = 1:numel(A)
cameraType = A{i};
legendText{i} = cameraType;
end
legend(legendText);
The resulting plot in the livescript is wrong: all the errorbars are in the center of each of the respective group
But if I put the same code in the command window the plot is correct
Can you explain me what is going on?
I am sure that I am doing something wrong but I can not understand why (I took the errorbar part from some code online, it seems right to me but idk…) Hello everyone,
I am using a livescript to present some data.. data is a 4×7 matrix, so nbars is 4, ngroups is 7
figure
labels = categorical({‘Mental Demand’ ‘Physical Demand’ ‘Temporal Demand’ ‘Performance’, ‘Effort’, ‘Frustration’, ‘Overall’});
b=bar(labels’,data’);
title(‘RAW NASA TLX’);
box off
hold on
% Calculate the number of groups and number of bars in each group
[ngroups,nbars] = size(data’);
% Get the x coordinate of the bars
x = nan(nbars,ngroups);
for i = 1:nbars
x(i,:) = b(i).XEndPoints;
end
% Plot the errorbars
errorbar(x’,data’,error’,’k’,’linestyle’,’none’);
hold off
legendText = cell(1, numel(A));
for i = 1:numel(A)
cameraType = A{i};
legendText{i} = cameraType;
end
legend(legendText);
The resulting plot in the livescript is wrong: all the errorbars are in the center of each of the respective group
But if I put the same code in the command window the plot is correct
Can you explain me what is going on?
I am sure that I am doing something wrong but I can not understand why (I took the errorbar part from some code online, it seems right to me but idk…) bar, errorbar, grouped MATLAB Answers — New Questions