Skip to content

Commit 2be1bce

Browse files
authored
Merge pull request matplotlib#10544 from matplotlib/auto-backport-of-pr-10538
Backport PR matplotlib#10538 on branch v2.2.x
2 parents 4658539 + 2bd81fb commit 2be1bce

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/matplotlib/offsetbox.py

+4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ def _get_packed_offsets(wd_list, total, sep, mode="fixed"):
8383
sep = 0
8484
offsets_ = np.cumsum([0] + [w + sep for w in w_list])
8585
offsets = offsets_[:-1]
86+
# this is a bit of a hack to avoid a TypeError when used
87+
# in conjugation with tight layout
88+
if total is None:
89+
total = 1
8690
return total, offsets
8791

8892
elif mode == "equal":

lib/matplotlib/tests/test_offsetbox.py

+16
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,19 @@ def test_offsetbox_loc_codes():
9898
anchored_box = AnchoredOffsetbox(loc=code, child=da)
9999
ax.add_artist(anchored_box)
100100
fig.canvas.draw()
101+
102+
103+
def test_expand_with_tight_layout():
104+
fig = plt.figure()
105+
axes = fig.add_subplot(111)
106+
107+
d1 = [29388871, 12448, 40, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108+
0, 0, 0]
109+
d2 = [28396236, 981940, 22171, 537, 123, 88, 41, 42, 40, 26, 26,
110+
84, 6, 2, 0, 0, 0, 0, 0]
111+
axes.plot(d1, label='series 1')
112+
axes.plot(d2, label='series 2')
113+
axes.legend(mode='expand')
114+
115+
# ### THIS IS WHERE THE CRASH HAPPENS
116+
plt.tight_layout(rect=[0, 0.08, 1, 0.92])

0 commit comments

Comments
 (0)