-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed
Milestone
Description
This is a follow up to #10476
After v2.2.0 came out, I expected my tool to start working again as the above bug had been fixed. Unfortunately, my minimal example was too minimal and there was a second, very similar, bug that was missed.
It seems that adding the argument ncol=5
to the axes.legend
call in the previous minimal example triggers the error that I'm now seeing.
Minimal example:
#!/usr/bin/env python
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
print matplotlib.__version__ # 2.2.0rc1
fig = plt.figure()
axes = fig.add_subplot(111)
d1 = [29388871, 12448, 40, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
d2 = [28396236, 981940, 22171, 537, 123, 88, 41, 42, 40, 26, 26, 84, 6, 2, 0, 0, 0, 0, 0]
axes.plot(d1, label='series 1')
axes.plot(d2, label='series 2')
axes.legend(ncol=5, mode='expand')
#### THIS IS WHERE THE CRASH HAPPENS
plt.tight_layout(rect=[0,0.08,1,0.92])
fig.savefig('test.png', format='png', bbox_inches='tight')
plt.close(fig)
$ python minimal_example.py
2.2.0
Traceback (most recent call last):
File "minimal_example.py", line 20, in <module>
plt.tight_layout(rect=[0,0.08,1,0.92])
File "/Users/ewels/miniconda2/envs/work/lib/python2.7/site-packages/matplotlib/pyplot.py", line 1366, in tight_layout
fig.tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
File "/Users/ewels/miniconda2/envs/work/lib/python2.7/site-packages/matplotlib/figure.py", line 2275, in tight_layout
pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
File "/Users/ewels/miniconda2/envs/work/lib/python2.7/site-packages/matplotlib/tight_layout.py", line 328, in get_tight_layout_figure
pad=pad, h_pad=h_pad, w_pad=w_pad)
File "/Users/ewels/miniconda2/envs/work/lib/python2.7/site-packages/matplotlib/tight_layout.py", line 115, in auto_adjust_subplotpars
if ax.get_visible()])
File "/Users/ewels/miniconda2/envs/work/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 4182, in get_tightbbox
bb.append(child._legend_box.get_window_extent(renderer))
File "/Users/ewels/miniconda2/envs/work/lib/python2.7/site-packages/matplotlib/offsetbox.py", line 266, in get_window_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "/Users/ewels/miniconda2/envs/work/lib/python2.7/site-packages/matplotlib/offsetbox.py", line 388, in get_extent_offsets
for c in self.get_visible_children()]
File "/Users/ewels/miniconda2/envs/work/lib/python2.7/site-packages/matplotlib/offsetbox.py", line 259, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "/Users/ewels/miniconda2/envs/work/lib/python2.7/site-packages/matplotlib/offsetbox.py", line 478, in get_extent_offsets
sep, self.mode)
File "/Users/ewels/miniconda2/envs/work/lib/python2.7/site-packages/matplotlib/offsetbox.py", line 81, in _get_packed_offsets
sep = (total - sum(w_list)) / (len(w_list) - 1.)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
Note that my full axes.label()
call is as follows:
axes.legend(loc='lower center', bbox_to_anchor=(0, -0.22, 1, .102), ncol=5, mode='expand', fontsize=8, frameon=False)
Matplotlib version
- Operating system: OSX, Linux
- Matplotlib version: v2.2.0
- Matplotlib backend (
print(matplotlib.get_backend())
): MacOSX - Python version: 2.7, 3.4, 3.5, 3.6
- Other libraries: MultiQC: https://github.com/ewels/MultiQC
matplotlib installed using pip, python installed using conda locally (OSX) and on Travis CI.
Pinging @tacaswell, @dstansby and @afvincent as you fixed the previous bug 😉
Metadata
Metadata
Assignees
Labels
No labels