X Tutup
Skip to content

Fix missing imshow() subplots when using tight_layout#6096

Closed
Hongyu1230 wants to merge 1 commit intomatplotlib:masterfrom
Hongyu1230:master
Closed

Fix missing imshow() subplots when using tight_layout#6096
Hongyu1230 wants to merge 1 commit intomatplotlib:masterfrom
Hongyu1230:master

Conversation

@Hongyu1230
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

X Tutup