increase the thickness + hide some lines generated in the pie chart

Hi! I generated this pie chart:
load matrix_new.mat
load color_matrix.mat
% ==========
labels = matrix_new(:,1);
percentages = matrix_new(:,2);
figure
p = pie(percentages);
hText = p(2:2:end);
set(hText,{'String'},compose('%d',labels));
[~,idx] = unique(compose('%d (%g%%)',matrix_new),'stable');
set(hText,'FontSize',5);
pPatch = p(1:2:end);
set(pPatch,{'FaceColor'},num2cell(color_matrix,2));
I would need to represent this pie chart by generating thicker lines at the separation from one color to another (see 'color_matrix'). So have a thicker line between row 9-10; 19-20; 30-31; 40-41; 50-51; 60-61; 64-65; 67-68; 69-70; 72-73; 73-1.
I thought of using the 'line' command however how can I determine the start and end coordinates of the line? The start coordinate should coincide with the center of the pie (I assume [0,0]). I would need to locate the other coordinate.
a = [0,0];
b = [??,??];
line(a,b,'Color','r','LineWidth',2);
The result to be achieved would be this:
Also I would like to hide some lines, for example rows 41 to 50 in 'color_matrix':

1 commentaire

Hi Alberto,
R2023B introduced a new function piechart that is recommended over pie. However, it does not appear that piechart allows for control over the individual wedge edges, unfortunately.

Connectez-vous pour commenter.

 Réponse acceptée

Matt J
Matt J le 12 Nov 2023
Modifié(e) : Matt J le 12 Nov 2023
What I would do is overlay another piechart on top of it (with transparent wedges, but thicker lines).
load matrix_new.mat
load color_matrix.mat
% ==========
labels = matrix_new(:,1);
percentages = matrix_new(:,2);
figure
p = pie(percentages);
hText = p(2:2:end);
set(hText,{'String'},compose('%d',labels));
[~,idx] = unique(compose('%d (%g%%)',matrix_new),'stable');
set(hText,'FontSize',5);
pPatch = p(1:2:end);
set(pPatch,{'FaceColor'},num2cell(color_matrix,2));
c=cumsum([0;percentages]);
c=c([10:10:end-1,end-1:end]);
hold on
P=pie(diff(c));
delete(P(2:2:end));
set(P(1:2:end),'LineWidth',2,'FaceAlpha',0,'EdgeColor','r');hold off

8 commentaires

Thank you for your answer. I solved the arrangement in the lines in the correct position!
c = cumsum([0;percentages]);
r = [1,10,20,31,41,51,61,65,68,70,73,74];
c_new = c(r);
hold on
P = pie(diff(c_new));
delete(P(2:2:end));
set(P(1:2:end),'LineWidth',2,'FaceAlpha',0,'EdgeColor','r');hold off
Also is there any way to 'hide' the pie chart lines?
Also is there any way to 'hide' the pie chart lines?
Which ones? The patch objects have a LineStyle property which can be set to 'none'.
I wanted to hide the black lines included between the red lines!
If you do that then, assuming you have one solid color between the red lines as in your OP, then the graphic reduces back to one pie chart again. Anyway, setting LineStyle='none' should work.
How can I apply what you wrote by hiding the lines to one slice of pie?
I was trying to highlight in yellow only the lines of interest but there is some error.
% c = cumsum([0;percentages]);
% r = 41:1:51; % r = [41,51];
c = cumsum(percentages(41:51));
r = 1:1:11;
c_new = c(r);
hold on
P = pie(diff(c_new));
delete(P(2:2:end));
set(P(1:2:end),'LineWidth',2,'FaceAlpha',0,'EdgeColor','y');hold off
Result:
I don't see any difference in the code from before other than EdgeColor='y'.
I already knew that! How can I select only the lines of interest?
I've already told you how to hide the lines of a particular patch. You set its LineStyle to 'none'.
load matrix_new.mat
load color_matrix.mat
% ==========
labels = matrix_new(:,1);
percentages = matrix_new(:,2);
figure
p = pie(percentages);
hText = p(2:2:end);
set(hText,{'String'},compose('%d',labels));
[~,idx] = unique(compose('%d (%g%%)',matrix_new),'stable');
set(hText,'FontSize',5);
pPatch = p(1:2:end);
set(pPatch,{'FaceColor'},num2cell(color_matrix,2));
set(pPatch(1:50),'LineStyle','none')
c=cumsum([0;percentages]);
c=c([10:10:end-1,end-1:end]);
hold on
P=pie(diff(c));
delete(P(2:2:end));
set(P(1:2:end),'LineWidth',2,'FaceAlpha',0,'EdgeColor','r');hold off

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by