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

8 visualizzazioni (ultimi 30 giorni)
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 Commento
Paul
Paul il 12 Nov 2023
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.

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 12 Nov 2023
Modificato: Matt J il 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 Commenti
Alberto Acri
Alberto Acri il 14 Nov 2023
I already knew that! How can I select only the lines of interest?
Matt J
Matt J il 14 Nov 2023
Modificato: Matt J il 14 Nov 2023
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

Accedi per commentare.

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