Closed
Description
Bug report
Bug summary
pyplot.legend()
throws an IndexError
when using pyplot.errorbar
with empty data arrays.
Code for reproduction
import matplotlib.pyplot as plt
plt.errorbar([], [], yerr=[], label="Blue")
plt.legend()
Actual outcome
Traceback (most recent call last):
File "legend_test.py", line 6, in <module>
plt.legend()
File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 3553, in legend
ret = gca().legend(*args, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/axes/_axes.py", line 538, in legend
self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/legend.py", line 385, in __init__
self._init_legend_box(handles, labels, markerfirst)
File "/usr/lib/python3/dist-packages/matplotlib/legend.py", line 654, in _init_legend_box
fontsize, handlebox))
File "/usr/lib/python3/dist-packages/matplotlib/legend_handler.py", line 119, in legend_artist
fontsize, handlebox.get_transform())
File "/usr/lib/python3/dist-packages/matplotlib/legend_handler.py", line 477, in create_artists
self.update_prop(coll, barlinecols[0], legend)
IndexError: tuple index out of range
Expected outcome
I expect to find a marker in the legend, and no data points in the plot.
This works with matplotlib 1.3.1.
Note also that it works as expected with plt.plot([], [], label="Blue")
and also with plot.errorbar([], [], label="Blue")
Matplotlib version
- Operating system: Ubuntu 16.04.3 LTS
- Matplotlib version: 1.5.1
- Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg - Python version: error can be reproduced in both 3.5.2 and 2.7.12
matplotlib was installed using apt