@@ -1084,6 +1084,11 @@ def _maybe_add_color(self, colors, kwds, style, i):
1084
1084
if has_color and (style is None or re .match ('[a-z]+' , style ) is None ):
1085
1085
kwds ['color' ] = colors [i % len (colors )]
1086
1086
1087
+ def _get_marked_label (self , label , col_num ):
1088
+ if self .on_right (col_num ):
1089
+ return label + ' (right)'
1090
+ else :
1091
+ return label
1087
1092
1088
1093
class KdePlot (MPLPlot ):
1089
1094
def __init__ (self , data , ** kwargs ):
@@ -1214,10 +1219,12 @@ def _make_plot(self):
1214
1219
1215
1220
newline = plotf (* args , ** kwds )[0 ]
1216
1221
lines .append (newline )
1217
- leg_label = label
1218
- if self .mark_right and self .on_right (i ):
1219
- leg_label += ' (right)'
1220
- labels .append (leg_label )
1222
+
1223
+ if self .mark_right :
1224
+ labels .append (self ._get_marked_label (label , i ))
1225
+ else :
1226
+ labels .append (label )
1227
+
1221
1228
ax .grid (self .grid )
1222
1229
1223
1230
if self ._is_datetype ():
@@ -1235,18 +1242,16 @@ def _make_ts_plot(self, data, **kwargs):
1235
1242
lines = []
1236
1243
labels = []
1237
1244
1238
- def to_leg_label (label , i ):
1239
- if self .mark_right and self .on_right (i ):
1240
- return label + ' (right)'
1241
- return label
1242
-
1243
1245
def _plot (data , col_num , ax , label , style , ** kwds ):
1244
1246
newlines = tsplot (data , plotf , ax = ax , label = label ,
1245
1247
style = style , ** kwds )
1246
1248
ax .grid (self .grid )
1247
1249
lines .append (newlines [0 ])
1248
- leg_label = to_leg_label (label , col_num )
1249
- labels .append (leg_label )
1250
+
1251
+ if self .mark_right :
1252
+ labels .append (self ._get_marked_label (label , col_num ))
1253
+ else :
1254
+ labels .append (label )
1250
1255
1251
1256
if isinstance (data , Series ):
1252
1257
ax = self ._get_ax (0 ) # self.axes[0]
@@ -1356,6 +1361,7 @@ class BarPlot(MPLPlot):
1356
1361
_default_rot = {'bar' : 90 , 'barh' : 0 }
1357
1362
1358
1363
def __init__ (self , data , ** kwargs ):
1364
+ self .mark_right = kwargs .pop ('mark_right' , True )
1359
1365
self .stacked = kwargs .pop ('stacked' , False )
1360
1366
self .ax_pos = np .arange (len (data )) + 0.25
1361
1367
if self .stacked :
@@ -1398,15 +1404,14 @@ def _make_plot(self):
1398
1404
rects = []
1399
1405
labels = []
1400
1406
1401
- ax = self ._get_ax (0 ) # self.axes[0]
1402
-
1403
1407
bar_f = self .bar_f
1404
1408
1405
1409
pos_prior = neg_prior = np .zeros (len (self .data ))
1406
1410
1407
1411
K = self .nseries
1408
1412
1409
1413
for i , (label , y ) in enumerate (self ._iter_data ()):
1414
+ ax = self ._get_ax (i )
1410
1415
label = com .pprint_thing (label )
1411
1416
kwds = self .kwds .copy ()
1412
1417
kwds ['color' ] = colors [i % len (colors )]
@@ -1419,8 +1424,6 @@ def _make_plot(self):
1419
1424
start = 0 if mpl .__version__ == "1.2.1" else None
1420
1425
1421
1426
if self .subplots :
1422
- ax = self ._get_ax (i ) # self.axes[i]
1423
-
1424
1427
rect = bar_f (ax , self .ax_pos , y , self .bar_width ,
1425
1428
start = start ,
1426
1429
** kwds )
@@ -1437,7 +1440,10 @@ def _make_plot(self):
1437
1440
start = start ,
1438
1441
label = label , ** kwds )
1439
1442
rects .append (rect )
1440
- labels .append (label )
1443
+ if self .mark_right :
1444
+ labels .append (self ._get_marked_label (label , i ))
1445
+ else :
1446
+ labels .append (label )
1441
1447
1442
1448
if self .legend and not self .subplots :
1443
1449
patches = [r [0 ] for r in rects ]
@@ -1537,7 +1543,10 @@ def plot_frame(frame=None, x=None, y=None, subplots=False, sharex=True,
1537
1543
Rotation for ticks
1538
1544
secondary_y : boolean or sequence, default False
1539
1545
Whether to plot on the secondary y-axis
1540
- If dict then can select which columns to plot on secondary y-axis
1546
+ If a list/tuple, which columns to plot on secondary y-axis
1547
+ mark_right: boolean, default True
1548
+ When using a secondary_y axis, should the legend label the axis of
1549
+ the various columns automatically
1541
1550
kwds : keywords
1542
1551
Options to pass to matplotlib plotting method
1543
1552
0 commit comments