Pie charts in subplot with different size
显示 更早的评论
Hi all!
I am trying to plot pie charts within a subplot. However, I don't know why the charts all come with different sizes. I have attached a figure as an example.
Is there a way to resize all charts so that they all have the same dimension?
Thank you!

6 个评论
Geoff Hayes
2021-3-5
Alberto - what is the code that you are using to create your pie charts and add them to the subplots? It looks like the first and third are roughly the same size but the middle one is definitely smaller....perhaps because of the number of slices and the labels that are being applied to each slice.
ALBERTO BASAGLIA
2021-3-5
Geoff Hayes
2021-3-5
Alberto - I suspect the issue is with the legend. If you move the legend to the south, then the pie charts seem to be roughly the same size.
Adam Danz
2021-3-5
I have the same hunch as Geoff. I think the longer legend strings in the 2nd pie chart results in a small diameter.
ALBERTO BASAGLIA
2021-3-6
Adam Danz
2021-3-6
I haven't tried it but this problem might not persist if you used tiledlayout rather than subplots.
回答(1 个)
Maadhav Akula
2021-3-8
Hi Alberto,
As @Adam Danz has rightly pointed out tiledlayout function will help you out and also as you mentioned you have other charts as well, you can utilize the 'flow' option in case the number of charts is unknown.
figure(2)
% subplot(1,3,1)
tiledlayout(1,3);
% Tile 1
nexttile;
par1=[1319 8513 12767 8074 789];
labels={'4%','27%','41%','26%','3%'};
p1=pie(par1,labels);
set(findobj(p1,'type','text'),'FontSize',17,'FontName','Arial')
title('NUMBER OF STORIES','FontSize',20,'FontName','Arial')
legend({'1 Story',' Stories','3 Stories','4 Stories','5 Stories'},'Location','eastoutside','FontSize',17,'FontName','Arial')
% Tile 2
% subplot(1,3,2)
nexttile;
par2=[17787 4834 3427 975 1174 2041 967];
labels={'57%','15%','11%','3%','4%','6%','3%'};
p2=pie(par2,labels);
set(findobj(p2,'type','text'),'FontSize',17,'FontName','Arial')
title('CONSTRUCTION PERIOD','FontSize',20,'FontName','Arial')
legend({'< 1860','1861-1919','1919-1945','1946-1961','1962-1971','1972-1975','1976-1981'},'Location','eastoutside','FontSize',17,'FontName','Arial')
% Tile 3
% subplot(1,3,3)
nexttile;
par3=[13551 6296];
labels={'68%','32%'};
p3=pie(par3,labels);
set(findobj(p3,'type','text'),'FontSize',17,'FontName','Arial')
title('RING BEAMS AND TIE RODS','FontSize',20,'FontName','Arial')
legend({'Present','Absent'},'Location','eastoutside','FontSize',17,'FontName','Arial')
Hope this helps!
类别
在 帮助中心 和 File Exchange 中查找有关 Pie Charts 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!