Effacer les filtres
Effacer les filtres

pie chart subdivision of a sector

5 vues (au cours des 30 derniers jours)
Maria Ali
Maria Ali le 26 Déc 2021
Commenté : Maria Ali le 26 Déc 2021
i have to create a pi chart as shown in the picture from the given data. how can i subdivide a sector as is shown in the picture

Réponse acceptée

Chunru
Chunru le 26 Déc 2021
x = [73.1 39.3 29.9 8.2 7.2 6.2];
xp = x/sum(x);
x1 = [xp(1:2) sum(xp(3:end))];
x2 = xp(3:end);
figure; hold on
theta0 = 0;
colors = ['r','g','b','c','m','y', 'w'];
for i=1:length(x1)
theta1 = theta0 + x1(i)*360;
theta = linspace(theta0, theta1, 50)';
%[0.5*cosd(theta); 1*cosd(flip(theta))], [0.5*sind(theta); 1*sind(flip(theta))]
patch([0.5*cosd(theta); 1*cosd(flip(theta))], [0.5*sind(theta); 1*sind(flip(theta))], colors(i));
text(0.75*cosd(mean(theta)), 0.75*sind(mean(theta)), num2str(i))
theta0 = theta1;
end
theta0 = sum(x1(1:end-1))*360;
for i=1:length(x2)
theta1 = theta0 + x2(i)*360;
theta = linspace(theta0, theta1, 50)';
%[0.5*cosd(theta); 1*cosd(flip(theta))], [0.5*sind(theta); 1*sind(flip(theta))]
patch([1*cosd(theta); 1.5*cosd(flip(theta))], [1*sind(theta); 1.5*sind(flip(theta))], colors(3));
text(1.25*cosd(mean(theta)), 1.25*sind(mean(theta)), char('A'+(i-1)))
theta0 = theta1;
end
axis equal
axis off
  1 commentaire
Maria Ali
Maria Ali le 26 Déc 2021
Thank you so much for your help.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by