Skip to content

Commit 7e50fa0

Browse files
committed
Title check checks for subplot length if specified
1 parent 9dd73d1 commit 7e50fa0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

pandas/plotting/_matplotlib/core.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,16 @@ def _adorn_subplots(self, fig: Figure) -> None:
802802
if self.title:
803803
if self.subplots:
804804
if is_list_like(self.title):
805-
if len(self.title) != self.nseries:
805+
if type(self.subplots) != bool:
806+
if len(self.subplots) != len(self.title):
807+
raise ValueError(
808+
"The length of `title` must equal the number "
809+
"of subplots if `title` of type `list` "
810+
"and subplots is iterable.\n"
811+
f"length of title = {len(self.title)}\n"
812+
f"number of subplots = {len(self.subplots)}"
813+
)
814+
elif len(self.title) != self.nseries:
806815
raise ValueError(
807816
"The length of `title` must equal the number "
808817
"of columns if using `title` of type `list` "

pandas/tests/plotting/test_misc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,9 @@ def test_plot_bar_label_count_expected_fail():
829829
)
830830
with pytest.raises(
831831
ValueError,
832-
match="The length of `title` must equal the number of columns "
833-
"if using `title` of type `list` and `subplots=True`.",
832+
match="The length of `title` must equal the number "
833+
"of subplots if `title` of type `list` "
834+
"and subplots is iterable.\n",
834835
):
835836
df.plot(
836837
subplots=[("A", "B")],

0 commit comments

Comments
 (0)