Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17dd254

Browse files
committed
issue informative warning when calling legend() without labelled objects.
svn path=/trunk/matplotlib/; revision=3507
1 parent dba51b2 commit 17dd254

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,6 +2960,9 @@ def get_handles():
29602960
if label is not None and label != '' and not label.startswith('_'):
29612961
handles.append(handle)
29622962
labels.append(label)
2963+
if len(handles) == 0:
2964+
warnings.warn("No labeled objects found. Use label='...' kwarg on individual plots.")
2965+
return None
29632966

29642967
elif len(args)==1:
29652968
# LABELS

0 commit comments

Comments
 (0)