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

Skip to content

Commit 384992f

Browse files
committed
Display only meaningful labels when calling legend() without args
svn path=/trunk/matplotlib/; revision=3349
1 parent 961fd20 commit 384992f

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2007-06-02 Display only meaningful labels when calling legend()
2+
without args. - NN
3+
14
2007-06-02 Have errorbar follow the color cycle even if line is not plotted.
25
Suppress plotting of errorbar caps for capsize=0. - NN
36

lib/matplotlib/axes.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,8 @@ def add_line(self, line):
10561056
line.set_clip_box(self.bbox)
10571057

10581058
self._update_line_limits(line)
1059-
label = line.get_label()
1060-
if not label: line.set_label('line%d'%len(self.lines))
1059+
if not l.get_label():
1060+
l.set_label('_line%d'%len(self.lines))
10611061
self.lines.append(line)
10621062

10631063
def _update_line_limits(self, line):
@@ -2890,10 +2890,10 @@ def get_handles():
28902890
if len(args)==0:
28912891
handles = []
28922892
labels = []
2893-
for line in get_handles():
2894-
label = line.get_label()
2895-
if label != '_nolegend_':
2896-
handles.append(line)
2893+
for handle in get_handles():
2894+
label = handle.get_label()
2895+
if label is not None and label != '' and label[0] != '_':
2896+
handles.append(handle)
28972897
labels.append(label)
28982898
loc = popd(kwargs, 'loc', 1)
28992899

@@ -2917,7 +2917,7 @@ def get_handles():
29172917
# LINES, LABELS, LOC
29182918
handles, labels, loc = args
29192919
else:
2920-
raise RuntimeError('Invalid arguments to legend')
2920+
raise TypeError('Invalid arguments to legend')
29212921

29222922

29232923
handles = flatten(handles)

0 commit comments

Comments
 (0)