Skip to content

Commit e1c601d

Browse files
authored
Allow handles to be passed as a nparray and not just a Python list
This is a one line edit. I replaced "if handles and labels:" with "if handles is not None and labels is not None:" I ran into an error when I passed the handles as a nparray instead of a Python list: "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()". I felt it should work for any iterable that contains the handles, and this tiny edit solved the issue with nparrays.
1 parent 462e6a6 commit e1c601d

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/matplotlib/legend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ def _parse_legend_args(axs, *args, handles=None, labels=None, **kwargs):
13631363
f"len(handles) = {len(handles)} "
13641364
f"len(labels) = {len(labels)}")
13651365
# if got both handles and labels as kwargs, make same length
1366-
if handles and labels:
1366+
if handles is not None and labels is not None:
13671367
handles, labels = zip(*zip(handles, labels))
13681368

13691369
elif handles is not None and labels is None:

0 commit comments

Comments
 (0)