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

Skip to content

Commit 2fd8362

Browse files
committed
Don't warn when legend() finds no labels.
There's no warning when calling `plot([])`, so I don't see why there should be one when calling `legend()` with no labeled artists either (except for catching basic bugs where someone forgets to pass `label=...`, but such errors are pretty obvious visually anyways and the warning doesn't help when only *some* labels are missing). Typical use case: making a complicated plot with a lot of elements which each may or may not have a label; now I need to separately keep track of whether I actually *did* add a label before deciding whether to call `legend()` at the end.
1 parent b65be40 commit 2fd8362

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Removal of warning on empty legends
2+
```````````````````````````````````
3+
4+
``plt.legend`` used to issue a warning when no labeled artist could be found.
5+
This warning has been removed.

lib/matplotlib/axes/_axes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,6 @@ def legend(self, *args, **kwargs):
531531
elif len(args) == 0:
532532
handles, labels = self.get_legend_handles_labels(handlers)
533533
if not handles:
534-
warnings.warn("No labelled objects found. "
535-
"Use label='...' kwarg on individual plots.")
536534
return None
537535

538536
# One argument. User defined labels - automatic handle detection.

0 commit comments

Comments
 (0)