matlab - Pie Chart Color -


how can create 2 different pie chart different colors?
say, have plot 2 different data:

  1. one of them has monday, tuesday, wednesday... (all days)
  2. and other 1 has monday, wednesday , sunday.

i want monday in chart 1 , monday in chart 2 have same color. same thing wednesday, etc.
tuesday , other days not appear in second plot in other color. possible?

using:

figure x = rand(5, 1); x = x/sum(x); p = pie(x, {'m', 't', 'w', 'th', 'f'}); figure x2 = rand(5, 1); x2(2) = 0; % remove tuesday plot x2 = x2/sum(x2); p = pie(x2, {'m', 't', 'w', 'th', 'f'}); 

gives:

image

a small hack set values of days want show a small positive value , use empty char array or char array space characters labels.

the smallest value in matlab can returned using realmin('double') or can use eps or manually define small positive value.

figure x = rand(7,1); x = x/sum(x); subplot(1,2,1); p = pie(x,{'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'});  subplot(1,2,2); x2 = rand(7,1); x2([2,4,5,6]) = realmin('double');  %<----- notice (setting small values) x2 = x2/sum(x2);                                 p = pie(x2,{'mon', '', 'wed', '', '', '', 'sun'}); %notice -------^----------^---^---^   no label tue, thur, fri, sat 

which gives:

out


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -