Pie charts in subplot with different size (2024)

32 views (last 30 days)

Show older comments

ALBERTO BASAGLIA on 5 Mar 2021

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size

Answered: Maadhav Akula on 8 Mar 2021

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!Pie charts in subplot with different size (2)

6 Comments

Show 4 older commentsHide 4 older comments

Geoff Hayes on 5 Mar 2021

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1370736

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1370736

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 on 5 Mar 2021

https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1370771

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1370771

Open in MATLAB Online

Hi Geoff, thanks for your reply. Please find the code below.

Tha chart in the middle is definitely smaller but also the one on the right is slightly bigger.

figure(2)

subplot(1,3,1)

par1=[1319 851312767 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')

subplot(1,3,2)

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')

subplot(1,3,3)

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')

Geoff Hayes on 5 Mar 2021

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1371246

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1371246

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 on 5 Mar 2021

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1371261

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1371261

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 on 6 Mar 2021

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1372966

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1372966

Thank you Geoff and Adam!

Unfortunately, I have to plot other charts with many values, so the legend at the bottom causes the same issues....

I solved it by plotting each chart separately and then merging them with an imaging software. It is slow but it works!

Adam Danz on 6 Mar 2021

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1373411

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#comment_1373411

I haven't tried it but this problem might not persist if you used tiledlayout rather than subplots.

Sign in to comment.

Sign in to answer this question.

Answers (1)

Maadhav Akula on 8 Mar 2021

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#answer_641651

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/763816-pie-charts-in-subplot-with-different-size#answer_641651

Open in MATLAB Online

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.

Your code modified using tiledlayout:

figure(2)

% subplot(1,3,1)

tiledlayout(1,3);

% Tile 1

nexttile;

par1=[1319 851312767 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!

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D PlotsData Distribution PlotsPie Charts

Find more on Pie Charts in Help Center and File Exchange

Tags

  • pie
  • piecharts
  • plot
  • subplot
  • size
  • resize

Products

  • MATLAB

Release

R2020b

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Pie charts in subplot with different size (10)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

Pie charts in subplot with different size (2024)
Top Articles
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 5947

Rating: 4 / 5 (41 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.