Matlab:明确指定饼图切片颜色 [英] Matlab: Explicitly specifying pie graph slice color

查看:993
本文介绍了Matlab:明确指定饼图切片颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个饼图.

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

是否可以显式更改各个切片的颜色?

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

例如;如果我希望a和b的切片始终为绿色,而c和d的切片始终为蓝色,而不管它们的大小如何,我该怎么做?在我看来,彩色图使用切片的大小来着色,而不一定是赋予饼图功能的顺序.

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.

推荐答案

饼图的颜色由轴颜色图确定.因此,定义一个矩阵,该矩阵的行数与饼形图的数量一样多,并将其用作颜色图.第一种颜色是指第一个值(a),等等.

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.

例如:

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

这篇关于Matlab:明确指定饼图切片颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆