Matlab: Explicitly specifying pie graph slice color

巧了我就是萌 提交于 2019-12-10 14:19:40

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/29858254/matlab-explicitly-specifying-pie-graph-slice-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!