Skip to content

Commit 9aa6c3c

Browse files
committed
Better tight layout empty slot handling (fix #313)
1 parent 87f098b commit 9aa6c3c

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

proplot/gridspec.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -709,30 +709,35 @@ def _get_tight_space(self, w):
709709
for i, (s, p) in enumerate(zip(space, pad)):
710710
# Find axes that abutt aginst this row or column space
711711
groups = []
712-
filt1 = ralong[:, 1] == i # i.e. r / b edge abutts against this
713-
filt2 = ralong[:, 0] == i + 1 # i.e. l / t edge abutts against this
714712
for j in range(nacross): # e.g. each row
715713
# Get the indices for axes that meet this row or column edge.
714+
# NOTE: Rigorously account for empty and overlapping slots here
716715
filt = (racross[:, 0] <= j) & (j <= racross[:, 1])
717716
if sum(filt) < 2:
718717
continue # no interface
719-
idx1, = np.where(filt & filt1)
720-
idx2, = np.where(filt & filt2)
721-
if not idx1.size or not idx2.size:
722-
continue
718+
ii = i
719+
idx1 = idx2 = np.array(())
720+
while ii >= 0 and idx1.size == 0:
721+
filt1 = ralong[:, 1] == ii # i.e. r / b edge abutts against this
722+
idx1, = np.where(filt & filt1)
723+
ii -= 1
724+
ii = i + 1
725+
while ii <= len(space) and idx2.size == 0:
726+
filt2 = ralong[:, 0] == ii # i.e. l / t edge abutts against this
727+
idx2, = np.where(filt & filt2)
728+
ii += 1
723729
# Put axes into unique groups and store as (l, r) or (b, t) pairs.
724730
axs1, axs2 = [axs[_] for _ in idx1], [axs[_] for _ in idx2]
725731
if x != 'x': # order bottom-to-top
726732
axs1, axs2 = axs2, axs1
727-
newgroup = True
728733
for (group1, group2) in groups:
729734
if any(_ in group1 for _ in axs1) or any(_ in group2 for _ in axs2):
730-
newgroup = False
731735
group1.update(axs1)
732736
group2.update(axs2)
733737
break
734-
if newgroup:
735-
groups.append([set(axs1), set(axs2)]) # form new group
738+
else:
739+
if axs1 and axs2:
740+
groups.append([set(axs1), set(axs2)]) # form new group
736741
# Determing the spaces using cached tight bounding boxes
737742
# NOTE: Set gridspec space to zero if there are no adjacent edges
738743
margins = []

0 commit comments

Comments
 (0)