Skip to content

Commit bfacfd8

Browse files
committed
wip
1 parent ab687ae commit bfacfd8

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pandas/plotting/_matplotlib/core.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,18 @@ def legend_title(self) -> Optional[str]:
579579
stringified = map(pprint_thing, self.data.columns.names)
580580
return ",".join(stringified)
581581

582-
def _add_legend_handle(self, handle, label, index=None):
582+
def _mark_right_label(
583+
self, label: Optional[str], index: Optional[int]
584+
) -> Optional[str]:
585+
if not self.subplots: # (right) is only attached when subplots=False
586+
if label is not None:
587+
if self.mark_right and index is not None:
588+
if self.on_right(index):
589+
label = label + " (right)"
590+
return label
591+
592+
def _add_legend_handle(self, handle: Artist, label: str) -> None:
583593
if label is not None:
584-
if self.mark_right and index is not None:
585-
if self.on_right(index):
586-
label = label + " (right)"
587594
self.legend_handles.append(handle)
588595
self.legend_labels.append(label)
589596

@@ -1174,6 +1181,7 @@ def _make_plot(self):
11741181
kwds = dict(kwds, **errors)
11751182

11761183
label = pprint_thing(label) # .encode('utf-8')
1184+
label = self._mark_right_label(label, index=i)
11771185
kwds["label"] = label
11781186

11791187
newlines = plotf(
@@ -1186,7 +1194,7 @@ def _make_plot(self):
11861194
is_errorbar=is_errorbar,
11871195
**kwds,
11881196
)
1189-
self._add_legend_handle(newlines[0], label, index=i)
1197+
self._add_legend_handle(newlines[0], label)
11901198

11911199
if self._is_ts_plot():
11921200

@@ -1462,6 +1470,7 @@ def _make_plot(self):
14621470
kwds = dict(kwds, **errors)
14631471

14641472
label = pprint_thing(label)
1473+
label = self._mark_right_label(label, index=i)
14651474

14661475
if (("yerr" in kwds) or ("xerr" in kwds)) and (kwds.get("ecolor") is None):
14671476
kwds["ecolor"] = mpl.rcParams["xtick.color"]
@@ -1512,7 +1521,7 @@ def _make_plot(self):
15121521
log=self.log,
15131522
**kwds,
15141523
)
1515-
self._add_legend_handle(rect, label, index=i)
1524+
self._add_legend_handle(rect, label)
15161525

15171526
def _post_plot_logic(self, ax: Axes, data):
15181527
if self.use_index:

pandas/plotting/_matplotlib/hist.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def _make_plot(self):
8989
kwds = self.kwds.copy()
9090

9191
label = pprint_thing(label)
92+
label = self._mark_right_label(label, index=i)
9293
kwds["label"] = label
9394

9495
style, kwds = self._apply_style_colors(colors, kwds, i, label)
@@ -105,7 +106,7 @@ def _make_plot(self):
105106
kwds["weights"] = weights[:, i]
106107

107108
artists = self._plot(ax, y, column_num=i, stacking_id=stacking_id, **kwds)
108-
self._add_legend_handle(artists[0], label, index=i)
109+
self._add_legend_handle(artists[0], label)
109110

110111
def _make_plot_keywords(self, kwds, y):
111112
"""merge BoxPlot/KdePlot properties to passed kwds"""

0 commit comments

Comments
 (0)