Closed
Description
Using plt.legend(labelcolor='linecolor') when there is an errorbar plot in the legend causes an error. I only have myself to blame, since I introduced this feature in #15898.
Here is an example that reproduces the problem:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 6)
y = np.sin(x)
plt.errorbar(x, y, yerr=0.1, label='y')
plt.legend(labelcolor='linecolor')
plt.show()
And here is the cryptic error message:
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_macosx.py", line 45, in _draw
self.figure.draw(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/artist.py", line 74, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/figure.py", line 2790, in draw
mimage._draw_list_compositing_images(
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/_api/deprecation.py", line 431, in wrapper
return func(*inner_args, **inner_kwargs)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 2921, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/legend.py", line 609, in draw
bbox = self._legend_box.get_window_extent(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 352, in get_window_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 438, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 438, in <listcomp>
whd_list = [c.get_extent(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 347, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 474, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 474, in <listcomp>
whd_list = [c.get_extent(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 347, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 438, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 438, in <listcomp>
whd_list = [c.get_extent(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 347, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 474, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 474, in <listcomp>
whd_list = [c.get_extent(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/offsetbox.py", line 823, in get_extent
bbox, info, yd = self._text._get_layout(renderer)
File "/Users/danhickstein/opt/anaconda3/lib/python3.9/site-packages/matplotlib/text.py", line 294, in _get_layout
if key in self._cached:
TypeError: unhashable type: 'numpy.ndarray'
I will try to work on this problem, but since it might be a few days before I have time, I thought that I would start the the issue here.