From fc7bc44dc5aa712b3d750bfd7029ac545aa727d9 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 31 Aug 2021 21:31:44 +0200 Subject: [PATCH] Make warning for no-handles legend more explicit. It may be slightly better to only emit the longer message if there were actually handles that got ignored because of the leading underscore, but that's actually a bit annoying to check (or requires some refactoring of _get_legend_handles_labels). --- lib/matplotlib/legend.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index 1d85ba1a3f27..6d956a29ee48 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -1224,7 +1224,10 @@ def _parse_legend_args(axs, *args, handles=None, labels=None, **kwargs): elif len(args) == 0: handles, labels = _get_legend_handles_labels(axs, handlers) if not handles: - log.warning('No handles with labels found to put in legend.') + log.warning( + "No artists with labels found to put in legend. Note that " + "artists whose label start with an underscore are ignored " + "when legend() is called with no argument.") # One argument. User defined labels - automatic handle detection. elif len(args) == 1: