Arrange numbers circularly around the pie chart
Show older comments
I create this graph chart:
matrix = importdata("matrix_out_INF.mat");
% ===============
% Filter the matrix to include only rows with percentage values < 5
matrix_new = matrix(matrix(:,2) < 5, :);
tot_percent_subgraph = sum(matrix_new(:,2));
% Extract the labels and corresponding percentages for the pie chart
labels = matrix_new(:,1);
percentages = matrix_new(:,2);
% 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_new(:, 1), matrix_new(:, 2), 'UniformOutput', false);
% Colore
pPatch = findobj(p, 'Type','Patch');
cm = colormap(turbo(numel(pPatch))); % Colour Array (Can Be Whatever You Define It To Be)
for k = 1:numel(label_str)
pPatch(k).FaceColor = cm(k,:); % Colour Each Patch Individually
% pText(k).FontSize = 12;
end
% Add labels to the pie chart
lgd = legend(label_str, 'Location', 'EastOutside','FontSize',12);
lgd.NumColumns = 2;

I would like:
1) Display around the pie chart only the values of 'labels1':
[r,c] = find(percentages == 0);
labels1 = labels;
labels1(r) = [];
2) Try to have a circular arrangement of numbers (see figure), without the numbers overlapping each other.

3) Possiblity to change the size of the numbers around the pie chart. I have tried this modification but it does not lead to any change:
[r,c] = find(percentages == 0);
% labels1 = labels;
% labels1(r) = [];
label_str_agg = label_str;
label_str_agg(r) = [];
for k1 = 1:numel(label_str_agg)
pText(k1).FontSize = 20;
end
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!
