Side-by-side Bar Graph Colors

조회 수: 2 (최근 30일)
Kevin
Kevin 2014년 6월 23일
답변: Star Strider 2014년 6월 23일
Y = [-3,-2;2,1;1,-1;4,3;-1,4];
bar(Y);
The above produces a graph with 5 X-axis ticks, each tick having 2 bars placed side by side. How can I specify the colors of each bar? That is, at each tick, I want the left bar to be a certain color and the right bar to be a certain color.
Thank you.

채택된 답변

Star Strider
Star Strider 2014년 6월 23일
This works:
Y = [-3,-2;2,1;1,-1;4,3;-1,4];
hb = bar(Y);
hbc = get(hb, 'Children');
set(hbc{1}, 'FaceColor', 'r') % Red bars for first column
set(hbc{2}, 'FaceColor', 'g') % Green bars for first column

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by