How to use two different color schemes in one bar chart?

3 views (last 30 days)
I want to put different color schemes to represent X and Y in the bar chart. I am trying to do it with colormap but unable to do it. I am getting something like this
But I want something as put one figure on the top of second.
X = [15,12,11
18,17,13
19,18,16
15,15,15
14,13,12];
Y = [5,2,1
8,7,3
9,8,6
5,5,5
4,3,2];
figure
wi=1;
bar(Y, wi);
colormap(cool)
hold on
bar(X, wi/4);
colormap(summer)
legend('One','Two', 'Three');

Accepted Answer

KL
KL on 24 Aug 2017
Edited: KL on 24 Aug 2017
figure
wi=1;
ax1 = subplot(2,1,1);
bar(Y, wi);
colormap(ax1,cool)
legend('One','Two', 'Three');
ax2 = subplot(2,1,2)
bar(X, wi/4);
colormap(ax2,summer)
legend('One','Two', 'Three');
  7 Comments
KL
KL on 4 Sep 2017
Try this.
figure
h1 = bar(X, 0.25);
cmap1 = cool(3);
h1(1).FaceColor = cmap1(1,:);
h1(2).FaceColor = cmap1(2,:);
h1(3).FaceColor = cmap1(3,:);
hold on
h2 = bar(Y, 1);
cmap2 = winter(3);
h2(1).FaceColor = cmap2(1,:);
h2(2).FaceColor = cmap2(2,:);
h2(3).FaceColor = cmap2(3,:);
legend('Series1','Series2', 'Series3','Series4','Series5', 'Series6');

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!