How can I explode consecutive pie chart wedges together?
Afficher commentaires plus anciens
I'm generating the below pie chart, which plots displays the percentage of occurrence of distinct events, and how many times these events do not occur. The pie chart is divided into a number of equal sized "larger" segments based on the num_events parameter. In the example, this is three (divided by the black lines). Within each of these segments the percentage of occurrence is shaded, while the percentage of non-occurrence is left white.
Would it be possible to explode the shaded region along with its neighboring white region, together as in the figure on the right?

num_events=3; % numTx has to be less than or equal to 7.
scenarios = 1;
begin_a = 97;
data = rand(scenarios,num_events);
figure
overlayCircleOnPieCharts(data,num_events);
%% Function to plot pie chart, remove the boundary and dividing lines.
function ax = overlayCircleOnPieCharts(clearance,num_events)
[numRowC,numColC] = size(clearance);
if numColC~=num_events
disp("Error: check unequal dimensions. Verify number of treatments.")
return;
end
c_matrix = 100*clearance; % convert data to percentages
nc_matrix = 100*ones(numRowC,numColC) - c_matrix; % calculate non-clearance percentages
n_nc_matrix = reshape([c_matrix;nc_matrix],size(c_matrix,1),[]); % reshape to have matrix with alternating columns of clearance non-clearance
norm_matrix = n_nc_matrix./(num_events*100); % normalizes the data
non_clearance_color = ones(num_events,3);
clearance_color = [hex2rgb('#1B9E77')
hex2rgb('#D95F02')
hex2rgb('#7570B3')
hex2rgb('#E7298A')
hex2rgb('#66A61E')
hex2rgb('#E6AB02')
hex2rgb('#A6761D')];
colrs = reshape([clearance_color(1:num_events,:)';non_clearance_color'],3,[])'; % creates colors correctly
tiledlayout('flow');
for k = 1:numRowC
a_pi = nexttile;
pie(norm_matrix(k,:));
hold on
% pie chart, with outlines removed
pi_bakery = gca;
pi_bakery.Colormap = colrs; % set colors, data contained in clearance matrix is shaded
pi_bakery.Children(2).EdgeAlpha = 0;
pi_bakery.Children(4).EdgeAlpha = 0;
pi_bakery.Children(6).EdgeAlpha = 0;
pi_bakery.Children(8).EdgeAlpha = 0;
pi_bakery.Children(10).EdgeAlpha = 0;
pi_bakery.Children(12).EdgeAlpha = 0;
% circle overlayed, divided in num_events equal sections
x_cent = 0;
y_cent=0;
r=1;
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x_cent;
yunit = r * sin(th) + y_cent;
plot(xunit, yunit,'k','LineWidth',2.5);
plot([x_cent x_cent],[y_cent y_cent+r],'k','LineWidth',3) % Top line
for j = 1:num_events%numTx [edit to get the code to run - Voss]
plot([x_cent (x_cent + r*sin(2*pi*((1+j)/num_events)))],[y_cent (y_cent +r*cos(2*pi*((1+j)/num_events)))],'k','LineWidth',2.5) % right hand side line
end
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Pie Charts dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



