Azzera filtri
Azzera filtri

pie chart subdivision of a sector

5 visualizzazioni (ultimi 30 giorni)
Maria Ali
Maria Ali il 26 Dic 2021
Commentato: Maria Ali il 26 Dic 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

Risposta accettata

Chunru
Chunru il 26 Dic 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

Più risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by