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);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1496629/image.png)
Is there a way to create the total outline of the pie chart?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1496634/image.png)
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!