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?

采纳的回答

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