Create Error bar and title into the bar chart

조회 수: 6 (최근 30일)
Megan
Megan 2020년 2월 19일
댓글: Adam Danz 2020년 5월 14일
Hi guys
I have a bar chart and I want to add a error bar. But I dont know how to do that.
I have added my data set and this is my bar chart:
figure();
scaleSelection = strcmp(scale,'like'); % use strcmp(), not "==".
barData = meanVariantsVelocity(scaleSelection);
bh = bar(barData);
bh.FaceColor = 'flat';
% Find which bars have velocity==50
velocitySelection = velocity == 50;
velocityBarIdx = ismember(find(scaleSelection), find(velocitySelection));
% Choose two colors
barColors = [0 0 1; 1 0 1];
% Color the vel=50 bars
cmap = barColors(velocityBarIdx+1,:);
bh.CData = cmap;
[vgroup, vg] = findgroups (clean_ds.variants);
title = ('like');
% % add x tick labels
ax = bh.Parent;
ax.XTick = 1:numel(barData);
ax.XTickLabel = vg;
ax.TickLabelInterpreter = 'none';
xtickangle(ax, 45) % or try 90 degrees
my title is also not working.
Do you guys can help me?
  댓글 수: 2
Rena Berman
Rena Berman 2020년 5월 14일
(Answers Dev) Restored edit
Adam Danz
Adam Danz 2020년 5월 14일
Copy of question
Hi guys
I have a bar chart and I want to add a error bar. But I dont know how to do that.
I have added my data set and this is my bar chart:
figure();
scaleSelection = strcmp(scale,'like'); % use strcmp(), not "==".
barData = meanVariantsVelocity(scaleSelection);
bh = bar(barData);
bh.FaceColor = 'flat';
% Find which bars have velocity==50
velocitySelection = velocity == 50;
velocityBarIdx = ismember(find(scaleSelection), find(velocitySelection));
% Choose two colors
barColors = [0 0 1; 1 0 1];
% Color the vel=50 bars
cmap = barColors(velocityBarIdx+1,:);
bh.CData = cmap;
[vgroup, vg] = findgroups (clean_ds.variants);
title = ('like');
% % add x tick labels
ax = bh.Parent;
ax.XTick = 1:numel(barData);
ax.XTickLabel = vg;
ax.TickLabelInterpreter = 'none';
xtickangle(ax, 45) % or try 90 degrees
my title is also not working.
Do you guys can help me?

댓글을 달려면 로그인하십시오.

답변 (1개)

Adam Danz
Adam Danz 2020년 2월 19일
편집: Adam Danz 2020년 2월 19일
Here's a simple demo you can follow to add errorbars to your bar plot.
If you get stuck applying that demo, share what you've got and I'd be happy to get you over the hump.
To fix the title problem
title('like'); % not title = ('like');

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by