create the complete outline of a pie chart characterized by values <1%
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi! I have a pie chart characterized by a single <1% slice. The graph that is plotted is only the segment as can be seen in the figure.
MMM = [1, 0.33];
labels = MMM(:,1);
percentages = MMM(:,2);
figure
p = pie(percentages);
hText = p(2:2:end);
set(hText,{'String'},compose('%d',labels));
[~,idx] = unique(compose('%d (%g%%)',MMM),'stable');
set(hText,'FontSize',14);
pPatch = p(1:2:end);
cm = [1 0 0];
set(pPatch,{'FaceColor'},num2cell(cm,2));
label_str = compose('%d (%g%%)',MMM);
lgd = legend(pPatch(idx),label_str,'Location','EastOutside','FontSize',14);
Is there a way to create the total outline of the pie chart?
댓글 수: 0
채택된 답변
Voss
2023년 9월 29일
편집: Voss
2023년 9월 29일
Here's one way (adding a separate call to line to create the circular outline):
MMM = [1, 0.33];
labels = MMM(:,1);
percentages = MMM(:,2);
figure
p = pie(percentages);
theta = linspace(0,2*pi,500);
line(cos(theta),sin(theta),'Color','k','LineWidth',2);
hText = p(2:2:end);
set(hText,{'String'},compose('%d',labels));
[~,idx] = unique(compose('%d (%g%%)',MMM),'stable');
set(hText,'FontSize',14);
pPatch = p(1:2:end);
cm = [1 0 0];
set(pPatch,{'FaceColor'},num2cell(cm,2));
label_str = compose('%d (%g%%)',MMM);
lgd = legend(pPatch(idx),label_str,'Location','EastOutside','FontSize',14);
(Note that 0.33 = 33% of the circe is shaded red, not 0.33% as shown in the legend. I don't know if that's what you intend or not.)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Title에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!