pie chart not complete - a pie is missing
Show older comments
HI! Why is the pie chart not complete? I would like to take into account the values present in 'matrix_analysis'.
load matrix_analysis.mat
labels = matrix_analysis(:,1);
percentages = matrix_analysis(:,2);
load legend_use.mat
% Create the pie chart with labels
figure
p = pie(percentages);
% Set 'TextType' property to 'none' to remove percentage labels
hText = findobj(p, 'Type', 'text');
percentValues = get(hText, 'String');
combinedText = strcat(percentValues, ' %');
for i = 1:numel(hText)
set(hText(i), 'String', '');
end
str = [string(labels') ""];
for k=1:numel(hText)
hText(k).String = str(k);
end
% Display the matrix_new values in the pie chart
label_str = arrayfun(@(x, y) sprintf('%d (%d%%)', x, y), matrix_analysis(:, 1), matrix_analysis(:, 2), 'UniformOutput', false);
% Dimension number around pie chart
for i=1:numel(labels)
strObj = findobj(p, 'String', labels(i)); % find the label in pie chart
set(strObj, 'FontSize', 14); % increase font size of label
end
pPatch = findobj(p, 'Type','Patch');
% Color
cm = colormap(turbo(numel(pPatch)));
for k = 1:numel(label_str)
pPatch(k).FaceColor = cm(k,:); % Colour Each Patch Individually
end
% Add labels to the pie chart
lgd = legend(legend_use, 'Location', 'EastOutside','FontSize',14);

Also, is it possible to arrange the numbers along the radius? In this way (example)!

Accepted Answer
More Answers (0)
Categories
Find more on Pie Charts in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

