Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix missing imshow() subplots when using tight_layout #6096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Fix missing imshow() subplots when using tight_layout #6096

wants to merge 1 commit into from

Conversation

Hongyu1230
Copy link

This is an attempt to fix the problem of missing subplot

The problem seems to be that when given space on the figure, the
subplots on the current figure will expand, this is fine if the subplots
on it currently are the final result, but will cause a problem when you
add further subplots to it due to the previously expanded subplot. My
attempted fix makes it so even when there is space it will only stay the
same, but if there isn't it will be smaller.

This is an attempt to fix the problem of missing subplot

The problem seems to be that when given space on the figure, the
subplots on the current figure will expand, this is fine if the subplots
on it currently are the final result, but will cause a problem when you
add further subplots to it due to the previously expanded subplot. My
attempted fix makes it so even when there is space it will only stay the
same, but if there isn't it will be smaller.
@tacaswell
Copy link
Member

One of the most common usages of tight_layout is to expand an axes to fill available space, does this break that?

I am some what surprised that this did not fail tests.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Mar 13, 2016
@tacaswell
Copy link
Member

I spent a while digging into this and do not yet understand it well enough to tell what is going wrong, however I am very sure that this is not the right fix.

By adding lots of print statements to test script

import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
seen_axes = set()
for i in range(16):
    print(len(fig.axes))
    ax = plt.subplot(4, 4, i + 1)
    seen_axes.add(ax)
    im = ax.imshow(np.random.normal(size=100).reshape([10, 10]))
    for a in fig.axes:
        print(a.bbox.bounds)
    print(len(fig.axes))
    plt.tight_layout()
    for a in fig.axes:
        print(a.bbox.bounds)
    plt.title(i)
    print(len(fig.axes))
    print('---')

plt.show()
print(ax.bbox.bounds)

You can see that something goes funny in the 2nd to last call to tight_layout where the axes get wider.

It really seems like this code could be replaced by half as much code, but still can not tell if this code is confusing because it is confusing, or confusing because it is doing something hard.

@tacaswell
Copy link
Member

'power-cycled' to trigger CI against current master.

@tacaswell tacaswell modified the milestones: 2.2 (next next feature release), 2.1 (next point release) Aug 13, 2017
@jklymak
Copy link
Member

jklymak commented May 8, 2018

OK, this seems very stale. Closing, but feel free to re-open if needed.

@jklymak jklymak closed this May 8, 2018
@story645 story645 removed this from the future releases milestone Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.