Number of registered results by the number of total experiments in a pie chart

1 visualización (últimos 30 días)
Hello Everyone,
I wonder if someone could help me with pie labels.
I have a vector of registered results, and I would show in the pie chart these numbers divided by the total cases.
I attached my beginner code, and truly hope someone will guide me.
Thanks in advance, and take care.
hEQ = [hEQUSA, hEQTurkey, hEQEU, hEQItaly, hEQGreece, hEQCAN];
sumhEQ = sum(hEQ);
figure()
labelsEQ = string(hEQ/sumhEQ);
legendLabelsEQ = {'EQ-USA', 'EQ-Turkey', 'EQ-EU', 'EQ-Italy', ...
'EQ-Greece', 'EQ-CAN'};
pie(hEQ, labelsEQ)
legend('labels', legendLabelsEQ, 'location', 'bestoutside')
For instance, hEQ is equal to [5 1 1 1 1 1]
so, sumhEQ is 10
and I would have labels like {'5/10', '1/10', '1/10', '1/10', '1/10', '1/10'}
Best.

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 20 de Jul. de 2021
Editada: Scott MacKenzie el 20 de Jul. de 2021
Here's one way to make the labels you want:
% test data
hEQ = [5 1 1 1 1 1];
% create labels for pie chart
total = sum(hEQ) * ones(1,length(hEQ));
s = sprintf('%d/%d ', [hEQ; total]);
labels = split(strtrim(s));
figure();
legendLabelsEQ = {'EQ-USA', 'EQ-Turkey', 'EQ-EU', 'EQ-Italy', ...
'EQ-Greece', 'EQ-CAN'};
pie(hEQ, labels);
legend('labels', legendLabelsEQ, 'location', 'bestoutside');
  2 comentarios
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco el 21 de Jul. de 2021
Dear Scott,
many thanks for your kind help, I can firmly say you are a reference for the MATLAB Community.
What, to say then, I wish you all the best.
---
Giuseppe
Scott MacKenzie
Scott MacKenzie el 21 de Jul. de 2021
@Giuseppe Degan Di Dieco You're welcome. Glad to help. And thanks for the kind words. Good luck with your research.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Pie Charts en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by