@@ -579,11 +579,17 @@ 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 ]:
583
585
if label is not None :
584
586
if self .mark_right and index is not None :
585
587
if self .on_right (index ):
586
588
label = label + " (right)"
589
+ return label
590
+
591
+ def _add_legend_handle (self , handle : Artist , label : str ) -> None :
592
+ if label is not None :
587
593
self .legend_handles .append (handle )
588
594
self .legend_labels .append (label )
589
595
@@ -1065,7 +1071,6 @@ def _make_plot(self):
1065
1071
label = self .label
1066
1072
else :
1067
1073
label = None
1068
-
1069
1074
scatter = ax .scatter (
1070
1075
data [x ].values ,
1071
1076
data [y ].values ,
@@ -1175,6 +1180,7 @@ def _make_plot(self):
1175
1180
kwds = dict (kwds , ** errors )
1176
1181
1177
1182
label = pprint_thing (label ) # .encode('utf-8')
1183
+ label = self ._mark_right_label (label , i )
1178
1184
kwds ["label" ] = label
1179
1185
1180
1186
newlines = plotf (
@@ -1187,8 +1193,7 @@ def _make_plot(self):
1187
1193
is_errorbar = is_errorbar ,
1188
1194
** kwds ,
1189
1195
)
1190
- if label is not None :
1191
- self ._add_legend_handle (newlines [0 ], label , index = i )
1196
+ self ._add_legend_handle (newlines [0 ], label )
1192
1197
1193
1198
if self ._is_ts_plot ():
1194
1199
@@ -1464,11 +1469,7 @@ def _make_plot(self):
1464
1469
kwds = dict (kwds , ** errors )
1465
1470
1466
1471
label = pprint_thing (label )
1467
-
1468
- if label is not None :
1469
- if self .mark_right and i is not None :
1470
- if self .on_right (i ):
1471
- label = label + " (right)"
1472
+ label = self ._mark_right_label (label , i )
1472
1473
1473
1474
if (("yerr" in kwds ) or ("xerr" in kwds )) and (kwds .get ("ecolor" ) is None ):
1474
1475
kwds ["ecolor" ] = mpl .rcParams ["xtick.color" ]
@@ -1519,8 +1520,7 @@ def _make_plot(self):
1519
1520
log = self .log ,
1520
1521
** kwds ,
1521
1522
)
1522
- if label is not None :
1523
- self ._add_legend_handle (rect , label , index = i )
1523
+ self ._add_legend_handle (rect , label )
1524
1524
1525
1525
def _post_plot_logic (self , ax : Axes , data ):
1526
1526
if self .use_index :
0 commit comments