Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab: Explicitly specifying pie graph slice color

I'm creating a pie graph.

pie([a,b,c,d]);

Is it possible to explicitly change the color of the individual slices?

For example; if I wanted the slices for a and b to always be green and c and d to always be blue, regardless of their size, how would I do that? It seems to me that a color map shades using the size of the slice not necessarily the order in which it was given to the pie function.

like image 430
warpstack Avatar asked Apr 24 '15 22:04

warpstack


1 Answers

The colors of the pie are determined by the axis colormap. So define a matrix with as many rows as the number of pie wedges, and use that as colormap. The first color refers to the first value (a), etc.

For example:

pie([3 2 4 1])
colormap([1 0 0;      %// red
          0 1 0;      %// green
          0 0 1;      %// blue
          .5 .5 .5])  %// grey

enter image description here

like image 112
Luis Mendo Avatar answered Nov 02 '22 10:11

Luis Mendo