How can I change colors and generate errorbars in a bar graph

조회 수: 35 (최근 30일)
LuoweiY
LuoweiY 2019년 10월 18일
댓글: Adam Danz 2019년 10월 18일
With the categorical data, how should I:
(1) set two bars into different colors
(2) create errorbars separately
data_1 = [1 2 3 4 5 6];
data_2 = [9 8 7 6 5 4];
mean_1 = mean(data_1);
mean_2 = mean(data_2)
x = categorical({'Variable_1', 'Variable_2'});
y = [mean_1, mean_2];
bar(x,y)
Many thanks!

채택된 답변

Adam Danz
Adam Danz 2019년 10월 18일
% Store the bar handle
bh = bar(x,y)
% Set the bar colors
bh.FaceColor = 'flat';
bh.CData = [1 0 0; 0 .5 0]; %red; green
% Set errorbars to +/- 0.5 and 1.0
hold on
eb = errorbar(x,y,[.5,1],'LineStyle','none','Color', 'k');
  댓글 수: 1
Adam Danz
Adam Danz 2019년 10월 18일
If you'd also like to get rid of the subscript in the x axis tick labels and show the underscore instead,
set(gca,'TickLabelInterpreter', 'none')

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by