Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8131131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:59:20+00:00 2026-06-06T08:59:20+00:00

I am plotting an array of pie charts, each using the same two colors

  • 0

I am plotting an array of pie charts, each using the same two colors for the same two types of data.

plt.figure(num=None, figsize=(6, 8))
for i in range(len(data_1)):
    plt.subplot(sp_rows, sp_cols, i+1)
    fracs = [data_1[i], data_2[i]]
    plt.pie(fracs, autopct='%1.1f%%')

pp.savefig()

Obviously it doesn’t make sense to plot a legend for every one of these charts, since they are all the same. So is there any way I can plot a single legend into a separate subfigure at the end?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:59:23+00:00Added an answer on June 6, 2026 at 8:59 am

    You can call legend() only once:

    import numpy as np
    import pylab as pl
    
    for i in xrange(1, 5):
        pl.subplot(220+i)
        pl.pie([i,2], labels=["a","b"], autopct='%1.1f%%')
    
    l = pl.legend(title="sample")
    pl.show()
    

    enter image description here

    or if you want the legend in a new axes, just create a dummy pie, and create legend for it, and then hide the dummy pie:

    import numpy as np
    import pylab as pl
    
    for i in xrange(1, 5):
        pl.subplot(220+i)
        pl.pie([i,2], labels=["a","b"], autopct='%1.1f%%')
    
    fig = pl.gcf()
    axe = fig.add_axes([0.4,0.4,0.2,0.2])
    
    pie = pl.pie([1,1], labels=["a","b"])
    l = pl.legend(title="sample", loc="center")
    for group in pie:
        for x in group:
            x.set_visible(False)
    
    pl.show()
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

plotting module def plotGraph(X,Y): fignum = random.randint(0,sys.maxint) plt.figure(fignum) ### Plotting arrangements ### return fignum
I'm plotting data in Python using matplotlib. I am updating the data of the
When plotting multiple data series using both line specification ( X , Y ,
I'm plotting the figure below using R's plot() function. It is a plot of
When plotting color-maps using gnuplot, I usually use the following lines: ... set palette
When plotting on a figure in MATLAB, I have noticed that parts of the
I am plotting boxplots from this data: MY_LABEL MY_REAL MY_CATEGORY 1 [POS] .56 POS
I'm plotting some data curves with gnuplot, and they look like this: However, the
When using the d3 plotting library Rickshaw the renderer (either area, line, or bar)
I have an array with dates as indices which I'm plotting. I'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.