Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Voss
Voss il 29 Set 2023
Modificato: Voss il 29 Set 2023
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.)

Più risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by