Fix missing imshow() subplots when using tight_layout#6096
Fix missing imshow() subplots when using tight_layout#6096Hongyu1230 wants to merge 1 commit intomatplotlib:masterfrom Hongyu1230:master
Conversation
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.
|
One of the most common usages of I am some what surprised that this did not fail tests. |
|
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 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. |
|
'power-cycled' to trigger CI against current master. |
|
OK, this seems very stale. Closing, but feel free to re-open if needed. |
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.