increase the thickness + hide some lines generated in the pie chart

7 次查看(过去 30 天)
Hi! I generated this pie chart:
load matrix_new.mat
load color_matrix.mat
% ==========
labels = matrix_new(:,1);
percentages = matrix_new(:,2);
figure
p = pie(percentages);
hText = p(2:2:end);
set(hText,{'String'},compose('%d',labels));
[~,idx] = unique(compose('%d (%g%%)',matrix_new),'stable');
set(hText,'FontSize',5);
pPatch = p(1:2:end);
set(pPatch,{'FaceColor'},num2cell(color_matrix,2));
I would need to represent this pie chart by generating thicker lines at the separation from one color to another (see 'color_matrix'). So have a thicker line between row 9-10; 19-20; 30-31; 40-41; 50-51; 60-61; 64-65; 67-68; 69-70; 72-73; 73-1.
I thought of using the 'line' command however how can I determine the start and end coordinates of the line? The start coordinate should coincide with the center of the pie (I assume [0,0]). I would need to locate the other coordinate.
a = [0,0];
b = [??,??];
line(a,b,'Color','r','LineWidth',2);
The result to be achieved would be this:
Also I would like to hide some lines, for example rows 41 to 50 in 'color_matrix':
  1 个评论
Paul
Paul 2023-11-12
Hi Alberto,
R2023B introduced a new function piechart that is recommended over pie. However, it does not appear that piechart allows for control over the individual wedge edges, unfortunately.

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2023-11-12
编辑:Matt J 2023-11-12
What I would do is overlay another piechart on top of it (with transparent wedges, but thicker lines).
load matrix_new.mat
load color_matrix.mat
% ==========
labels = matrix_new(:,1);
percentages = matrix_new(:,2);
figure
p = pie(percentages);
hText = p(2:2:end);
set(hText,{'String'},compose('%d',labels));
[~,idx] = unique(compose('%d (%g%%)',matrix_new),'stable');
set(hText,'FontSize',5);
pPatch = p(1:2:end);
set(pPatch,{'FaceColor'},num2cell(color_matrix,2));
c=cumsum([0;percentages]);
c=c([10:10:end-1,end-1:end]);
hold on
P=pie(diff(c));
delete(P(2:2:end));
set(P(1:2:end),'LineWidth',2,'FaceAlpha',0,'EdgeColor','r');hold off
  8 个评论
Matt J
Matt J 2023-11-14
编辑:Matt J 2023-11-14
I've already told you how to hide the lines of a particular patch. You set its LineStyle to 'none'.
load matrix_new.mat
load color_matrix.mat
% ==========
labels = matrix_new(:,1);
percentages = matrix_new(:,2);
figure
p = pie(percentages);
hText = p(2:2:end);
set(hText,{'String'},compose('%d',labels));
[~,idx] = unique(compose('%d (%g%%)',matrix_new),'stable');
set(hText,'FontSize',5);
pPatch = p(1:2:end);
set(pPatch,{'FaceColor'},num2cell(color_matrix,2));
set(pPatch(1:50),'LineStyle','none')
c=cumsum([0;percentages]);
c=c([10:10:end-1,end-1:end]);
hold on
P=pie(diff(c));
delete(P(2:2:end));
set(P(1:2:end),'LineWidth',2,'FaceAlpha',0,'EdgeColor','r');hold off

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Pie Charts 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by