@@ -579,11 +579,18 @@ def legend_title(self) -> Optional[str]:
579
579
stringified = map (pprint_thing , self .data .columns .names )
580
580
return "," .join (stringified )
581
581
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 :
583
593
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)"
587
594
self .legend_handles .append (handle )
588
595
self .legend_labels .append (label )
589
596
@@ -1174,6 +1181,7 @@ def _make_plot(self):
1174
1181
kwds = dict (kwds , ** errors )
1175
1182
1176
1183
label = pprint_thing (label ) # .encode('utf-8')
1184
+ label = self ._mark_right_label (label , index = i )
1177
1185
kwds ["label" ] = label
1178
1186
1179
1187
newlines = plotf (
@@ -1186,7 +1194,7 @@ def _make_plot(self):
1186
1194
is_errorbar = is_errorbar ,
1187
1195
** kwds ,
1188
1196
)
1189
- self ._add_legend_handle (newlines [0 ], label , index = i )
1197
+ self ._add_legend_handle (newlines [0 ], label )
1190
1198
1191
1199
if self ._is_ts_plot ():
1192
1200
@@ -1462,6 +1470,7 @@ def _make_plot(self):
1462
1470
kwds = dict (kwds , ** errors )
1463
1471
1464
1472
label = pprint_thing (label )
1473
+ label = self ._mark_right_label (label , index = i )
1465
1474
1466
1475
if (("yerr" in kwds ) or ("xerr" in kwds )) and (kwds .get ("ecolor" ) is None ):
1467
1476
kwds ["ecolor" ] = mpl .rcParams ["xtick.color" ]
@@ -1512,7 +1521,7 @@ def _make_plot(self):
1512
1521
log = self .log ,
1513
1522
** kwds ,
1514
1523
)
1515
- self ._add_legend_handle (rect , label , index = i )
1524
+ self ._add_legend_handle (rect , label )
1516
1525
1517
1526
def _post_plot_logic (self , ax : Axes , data ):
1518
1527
if self .use_index :
0 commit comments