@@ -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 :
0 commit comments