How can I change the color of the slices in my pie chart?
41 次查看(过去 30 天)
显示 更早的评论
How can I change the color of the slices in the pie chart?
*R_Pie(1).FaceColor = 'g' will change the color of the first slice but when running the line below it I get the error: " Unrecognized property 'FaceColor' for class 'matlab.graphics.primitive.Text' "
An example of my attempt is below.
TT = 10
RT = 25
TN = 2
RN = 3
R = [RT , RN]
T = [TT , TN]
subplot(2,2,1)
R_Pie = pie(R)
R_Pie(1).FaceColor = 'g'
R_Pie(2).FaceColor = 'r'
subplot(2,2,2)
T_Pie = pie(T)
T_Pie(1).FaceColor = 'g'
T_Pie(2).FaceColor = 'r'
0 个评论
采纳的回答
Voss
2023-7-12
TT = 10;
RT = 25;
TN = 2;
RN = 3;
R = [RT , RN];
T = [TT , TN];
subplot(2,2,1)
R_Pie = pie(R)
Notice the elements of R_Pie alternate Patch, Text, Patch, Text, ... Therefore, the second slice is the third element of R_Pie.
R_Pie(1).FaceColor = 'g';
R_Pie(3).FaceColor = 'r';
subplot(2,2,2)
T_Pie = pie(T)
T_Pie(1).FaceColor = 'g';
T_Pie(3).FaceColor = 'r';
2 个评论
Voss
2023-7-12
Something like this?
TT = 10;
RT = 25;
TN = 2;
RN = 3;
R = [RT , RN];
T = [TT , TN];
subplot(2,2,1)
R_Pie = pie(R);
R_Pie(1).FaceColor = 'g';
R_Pie(3).FaceColor = 'r';
R_Pie(2).String = sprintf('RT: %d\n%s',RT,R_Pie(2).String);
R_Pie(4).String = sprintf('RN: %d\n%s',RN,R_Pie(4).String);
subplot(2,2,2)
T_Pie = pie(T);
T_Pie(1).FaceColor = 'g';
T_Pie(3).FaceColor = 'r';
T_Pie(2).String = sprintf('TT: %d\n%s',TT,T_Pie(2).String);
T_Pie(4).String = sprintf('TN: %d\n%s',TN,T_Pie(4).String);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axes Appearance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!