Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2fd8362

Browse filesBrowse 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
Copy full SHA for 2fd8362

File tree

Expand file treeCollapse file tree

2 files changed

+5
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+5
-2
lines changed
+5Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.