Matlab: Explicit definition of the color of the cutoff of a circular graph

I am creating a pie chart.

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

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

For instance; 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 it? It seems to me that the color map of the shades using the slice size is not necessarily the order in which it was set for the pie function.

+4
source share
1 answer

The colors of the cake are determined by the color palette of the axis. Therefore, define a matrix with as many rows as the number of cliches for the pie, and use it as a color. The first color refers to the first value ( a), etc.

:

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

+5

Source: https://habr.com/ru/post/1584576/


All Articles