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

9 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2023 年 11 月 12 日
編集済み: Matt J 2023 年 11 月 14 日
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 件のコメント
Paul
Paul 2023 年 11 月 12 日
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.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2023 年 11 月 12 日
編集済み: Matt J 2023 年 11 月 12 日
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 件のコメント
Alberto Acri
Alberto Acri 2023 年 11 月 14 日
I already knew that! How can I select only the lines of interest?
Matt J
Matt J 2023 年 11 月 14 日
編集済み: Matt J 2023 年 11 月 14 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePie Charts についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by