How to insert both value and percentage in pie chart?
49 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all,
I just want to know how to insert in the same pie chart the values that comprise the already presented percentage?
This is the code
figure
xe=[5, 20, 15];
explode=[ 1 0 1];
pe=pie(xe, explode);
%%%% tagging
pText = findobj(pe,'Type','text');
percentValues = get(pText,'String');
txt = {'Geothermal: '; 'PV: '; 'EVs: '};
combinedtxt = strcat(txt,percentValues);
%%%%Set text
pText(1).String = combinedtxt(1);
pText(2).String = combinedtxt(2);
pText(3).String = combinedtxt(3);
0 commentaires
Réponse acceptée
dpb
le 2 Août 2022
That's another terrible user interface/oversight to go along with bar -- hadn't ever used it in MATLAB before; pie charts just are a format I used rarely, if ever...anyways, that aside you've got to build them yourselves it seems, but isn't too difficult, just annoying--
labels=compose('%s: %d (%0.1f%%)',string(txt),xe(:),100*xe(:)/sum(xe));
hP=pie(xe,explode,labels)
works -- you might want to try
labels=compose('%s: %d \n(%0.1f%%)',string(txt),xe(:),100*xe(:)/sum(xe));
and 'spearmint about alternate formatting.
NB: You'll have better luck and the above assumes the trailing ":" and blanks have been removed from the variable names/section names.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Pie Charts dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!