change the legend of a pie chart
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi. I have the following pie chart:
matrix_new = importdata("matrix_new.mat"); % import
labels = matrix_new(:,1);
percentages = matrix_new(:,2);
figure
p = pie(percentages);
hText = p(2:2:end);
set(hText,{'String'},compose('%d',labels));
label_str = compose('%d (%g%%)',matrix_new);
% label_str_new = importdata("label_str_new.mat"); % import
% label_str = label_str_new;
set(hText,'FontSize',12);
pPatch = p(1:2:end);
cm_c = importdata("cm_c.mat"); % import
set(pPatch,{'FaceColor'},num2cell(cm_c,2));
lgd = legend(label_str,'Location','EastOutside','FontSize',12);
lgd.NumColumns = 4;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1491027/image.png)
I need to transform the legend like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1491032/image.png)
0 Commenti
Risposta accettata
Voss
il 23 Set 2023
matrix_new = importdata("matrix_new.mat"); % import
labels = matrix_new(:,1);
percentages = matrix_new(:,2);
figure
p = pie(percentages);
hText = p(2:2:end);
set(hText,{'String'},compose('%d',labels));
label_str = compose('%d (%g%%)',matrix_new);
% label_str_new = importdata("label_str_new.mat"); % import
% label_str = label_str_new;
set(hText,'FontSize',12);
pPatch = p(1:2:end);
cm_c = importdata("cm_c.mat"); % import
set(pPatch,{'FaceColor'},num2cell(cm_c,2));
[legend_labels,idx] = unique(label_str,'stable');
lgd = legend(pPatch(idx),legend_labels,'Location','EastOutside','FontSize',12);
2 Commenti
Voss
il 24 Set 2023
matrix_new = importdata("matrix_new.mat"); % import
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',12);
pPatch = p(1:2:end);
cm_c = importdata("cm_c.mat"); % import
set(pPatch,{'FaceColor'},num2cell(cm_c,2));
label_str = load('label_str_new.mat');
label_str = label_str.label_str_new;
lgd = legend(pPatch(idx),label_str,'Location','EastOutside','FontSize',12);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Distribution Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!