필터 지우기
필터 지우기

create the complete outline of a pie chart characterized by values ​​<1%

조회 수: 1 (최근 30일)
Alberto Acri
Alberto Acri 2023년 9월 29일
편집: Voss 2023년 9월 29일
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?

채택된 답변

Voss
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개)

카테고리

Help CenterFile Exchange에서 Title에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by