-
Notifications
You must be signed in to change notification settings - Fork 98
Closed
Labels
Milestone
Description
Description
If multiple kinds of line are plotted on the figure, the legend() doesn't work.
Steps to reproduce
import proplot as pplt
import numpy as np
state = np.random.RandomState(51423)
data = (state.rand(10, 5) - 0.5).cumsum(axis=0)
fig, axs = pplt.subplots()
data = state.rand(20)
l1 = axs.plot(data, label='l1')
l2 = axs.plot(data*2, label='l2')
l3 = axs.axhline(0.5, c='green', label='l3')
axs.legend([l1, l2, l3], loc='r')Expected behavior
proplot 0.6.4 works well:

Actual behavior
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_31462/545939102.py in <module>
11 l3 = axs.axhline(0.5, c='green', label='l3')
12 # axs.legend([l1, l2], loc='r')
---> 13 axs.legend([l1, l2, l3], loc='r')
~/new/miniconda3/envs/pyresample_min/lib/python3.8/site-packages/proplot/ui.py in _iterator(*args, **kwargs)
780 result = []
781 for func in objs:
--> 782 result.append(func(*args, **kwargs))
783 if len(self) == 1:
784 return result[0]
~/new/miniconda3/envs/pyresample_min/lib/python3.8/site-packages/proplot/axes/base.py in legend(self, handles, labels, loc, width, space, queue, **kwargs)
1869 if loc in ('left', 'right', 'top', 'bottom'):
1870 ax = self.panel_axes(loc, width=width, space=space, filled=True)
-> 1871 obj = ax.legend(handles, labels, loc='fill', **kwargs)
1872 self._add_colorbar_legend(loc, obj, legend=True) # add to *this* axes
1873 return obj
~/new/miniconda3/envs/pyresample_min/lib/python3.8/site-packages/proplot/axes/base.py in legend(self, handles, labels, loc, width, space, queue, **kwargs)
1895
1896 # Generate legend
-> 1897 obj = wrap.legend_extras(self, handles, labels, loc=loc, **kwargs)
1898 self._add_colorbar_legend(loc, obj, legend=True) # possibly replace another
1899 return obj
~/new/miniconda3/envs/pyresample_min/lib/python3.8/site-packages/proplot/axes/plot.py in legend_extras(self, handles, labels, loc, ncol, ncols, center, order, label, title, fontsize, fontweight, fontcolor, color, marker, lw, linewidth, dashes, linestyle, markersize, frameon, frame, **kwargs)
4344 if list_of_lists:
4345 if any(not np.iterable(_) for _ in handles):
-> 4346 raise ValueError(f'Invalid handles={handles!r}.')
4347 if not labels:
4348 labels = [None] * len(handles)
ValueError: Invalid handles=[[<matplotlib.lines.Line2D object at 0x7ffacb87cfd0>], [<matplotlib.lines.Line2D object at 0x7ffacb87cca0>], <matplotlib.lines.Line2D object at 0x7ffa42564d90>].
Proplot version
matplotlib: 3.3.4
proplot: 0.7.0