How to Create a seperate colormap for each pi-chart in a subplot

2 views (last 30 days)
if true
% code
labels={'A','B','C','D','E','F'};
data=[22,19,11,16,11,21]';
wedge=[0,0,0,0,0,1]';
figure
subplot(1,3,1);
pie(data,wedge,labels);
colormap([0,0,1;0,1,1;0,1,0;1,0,0;1,0,1;0,0,0]);
title('Raw Data')
subplot(1,3,2);
pie(data(1:end-1),labels(1:end-1));
% colormap([0,0,1;0,1,1;0,1,0;1,0,0;1,0,1]);
title('Data Excluding F');
subplot(1,3,3);
data2=[(data(1)+data(2)),data(3),(data(4)+data(5))]';
labels2={'A+B','C','D+E'};
pie(data2,labels2);
% colormap([0,0,1;0,1,1;0,1,0]);
title('Groups');
end
If only the the first colormap is run: </matlabcentral/answers/uploaded_files/133805/CM1.PNG> If the first line and second colormap is run, the second one applies the second colormap to the first subplots: </matlabcentral/answers/uploaded_files/133806/CM2.PNG> If the first line second and third colormap is run, the third one applies the second colormap to the first and second subplots: </matlabcentral/answers/uploaded_files/133807/CM3.PNG>
How can I specify an individual colormap for each subplot?

Accepted Answer

jonas
jonas on 26 Sep 2018
Edited: jonas on 26 Sep 2018
just insert the handle as the first argument of colormap
colormap(gca,cmap);
minimal working example
subplot(1,2,1);
peaks
colormap(gca,'hot')
subplot(1,2,2);
peaks
colormap(gca,'jet')
  1 Comment
Philip Yip
Philip Yip on 27 Sep 2018
Thanks! That worked.
if true
% code
if true
% code
labels={'A','B','C','D','E','F'};
data=[22,19,11,16,11,21]';
wedge=[0,0,0,0,0,1]';
figure
subplot(1,3,1);
pie(data,wedge,labels);
colormap(gca,[0,0,1;0,1,1;0,1,0;1,0,0;1,0,1;0,0,0]);
title('Raw Data')
subplot(1,3,2);
pie(data(1:end-1),labels(1:end-1));
colormap(gca,[0,0,1;0,1,1;0,1,0;1,0,0;1,0,1]);
title('Data Excluding F');
subplot(1,3,3);
data2=[(data(1)+data(2)),data(3),(data(4)+data(5))]';
labels2={'A+B','C','D+E'};
pie(data2,labels2);
colormap(gca,[0,0,1;0,1,1;0,1,0]);
title('Groups');
end
end

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!