increase the thickness + hide some lines generated in the pie chart
조회 수: 6 (최근 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
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
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
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 Center 및 File Exchange에서 Pie Charts에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!