Skip to content

Commit 71bdbd4

Browse files
Added legend_loc parameter to plot function
1 parent 1028791 commit 71bdbd4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pandas/plotting/_matplotlib/core.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def __init__(
173173
stacked: bool = False,
174174
label: Hashable | None = None,
175175
style=None,
176+
legend_loc: str | tuple[float, float] ='best',
176177
**kwds,
177178
) -> None:
178179
# if users assign an empty list or tuple, raise `ValueError`
@@ -241,6 +242,8 @@ def __init__(
241242
self.legend = legend
242243
self.legend_handles: list[Artist] = []
243244
self.legend_labels: list[Hashable] = []
245+
self.legend_loc = legend_loc
246+
244247

245248
self.logx = type(self)._validate_log_kwd("logx", logx)
246249
self.logy = type(self)._validate_log_kwd("logy", logy)
@@ -909,7 +912,8 @@ def _make_legend(self) -> None:
909912
title = self.legend_title
910913

911914
if len(handles) > 0:
912-
ax.legend(handles, labels, loc="best", title=title)
915+
# ax.legend(handles, labels, loc="best", title=title)
916+
ax.legend(handles, labels, loc=self.legend_loc, title=title)
913917

914918
elif self.subplots and self.legend:
915919
for ax in self.axes:
@@ -920,7 +924,8 @@ def _make_legend(self) -> None:
920924
"No artists with labels found to put in legend.",
921925
UserWarning,
922926
)
923-
ax.legend(loc="best")
927+
# ax.legend(loc="best")
928+
ax.legend(loc=self.legend_loc)
924929

925930
@final
926931
@staticmethod

0 commit comments

Comments
 (0)