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 6355373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:45:10+00:00 2026-05-24T22:45:10+00:00

So in a figure where three vertical subplots have been added with add_subplot ,

  • 0

So in a figure where three vertical subplots have been added with add_subplot, how can I select let’s say the middle one?

Right now I do this list comprehension:

[r[0] for r in sorted([[ax, ax.get_geometry()[2]] for ax in self.figure.get_axes()], key=itemgetter(1))]

where I can simply select the index I want, with the corresponding axes. Is there a more straightforward way of doing this?

  • 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-05-24T22:45:10+00:00Added an answer on May 24, 2026 at 10:45 pm

    From the matplotlib documentation:

    If the figure already has a subplot with key (args, kwargs) then it will simply make that subplot current and return it.

    Here’s an example:

    import matplotlib.pyplot as plt
    
    fig = plt.figure()  
    for vplot in [1,2,3]:
        ax = fig.add_subplot(3,1,vplot)
        ax.plot(range(10),range(10))
    
    ax_again = fig.add_subplot(3,1,2)
    ax_again.annotate("The middle one",xy=(7,5),xytext=(7,5))
    
    plt.show()
    

    The middle plot is called again so that it can be annotated.

    What if I set the background with my original call, do I need to set it again when I get the subplot the second time?

    Yes. The arguments and keywords for the original call are used to make a unique identifier. So for the figure to generate this unique identifier again, you need to pass the same arguments (grid definition, position) and keywords again. For example:

    import matplotlib.pyplot as plt
    
    fig = plt.figure()  
    ax = fig.add_subplot(2,1,1,axisbg='red')
    ax.plot(range(10),range(10))
    ax = fig.add_subplot(2,1,2)
    ax.plot(range(10),range(10))
    
    ax_again = fig.add_subplot(2,1,1,axisbg='red')
    ax_again.annotate("The top one",xy=(7,5),xytext=(7,5))
    
    plt.show()
    

    What if I use ax_again.change_geometry() ?

    You would think change_geometry, e.g. from a 312 to a 422, would change how you use add_subplot, but it doesn’t. There appears to be a bug or undefined behavior when you call change_geometry. The unique key that was original generated using the arguments and keywords, to the first add_subplot call, does not get updated. Therefore, if you want to get an axis back with an add_subplot call, you need to call add_subplot with the original arguments and keywords. For more info, follow this issue report:
    https://github.com/matplotlib/matplotlib/issues/429

    My guess for now is that if you change any property of the subplot after generating it with add_subplot call, the unique will not be adjusted. So just use the original arguments and keywords, and hopefully this will work out.

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

Sidebar

Related Questions

I'm trying to figure out why this doesn't work. Let's say you three models,
I have built a layout that can display a picture on three different areas.
I would like to have three plots in a single figure. The figure should
I just can't figure it out. I have this shape in res/drawable/start_light.xml <?xml version=1.0
So I have a div sandwich: three divs on top of one another. The
I'm trying to figure out if there is any way to have a .NET
I'm trying to figure out how to define a vertical line (1dp thick) to
i create three circles. if a circle is dragged to right side of the
I have a div with links in it. And I'm lining them up one
I have a layout with a middle aligned paging. The paging is middle-aligned be

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.