From 4fe2ab215f8689302f4aa2dc3f5f07717cd5f247 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 2 Jul 2024 09:13:04 -0700 Subject: [PATCH 1/2] TST: Address UserWarning in matplotlib test --- pandas/plotting/_matplotlib/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 22be9baf1ff5c..23bfdb5a131e2 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -892,7 +892,7 @@ def _make_legend(self) -> None: elif self.subplots and self.legend: for ax in self.axes: - if ax.get_visible(): + if ax.get_visible() and ax.get_label(): ax.legend(loc="best") @final From 45741daf7ff2f5e5db9874d9b11162621d24bb3e Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:09:27 -0700 Subject: [PATCH 2/2] Filter the warning instead --- pandas/plotting/_matplotlib/core.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 23bfdb5a131e2..8b108346160d6 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -892,8 +892,14 @@ def _make_legend(self) -> None: elif self.subplots and self.legend: for ax in self.axes: - if ax.get_visible() and ax.get_label(): - ax.legend(loc="best") + if ax.get_visible(): + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + "No artists with labels found to put in legend.", + UserWarning, + ) + ax.legend(loc="best") @final @staticmethod