@@ -909,13 +909,9 @@ def _args_adjust(self):
909
909
pass
910
910
911
911
def _maybe_right_yaxis (self , ax ):
912
- _types = (list , tuple , np .ndarray )
913
- sec_true = isinstance (self .secondary_y , bool ) and self .secondary_y
914
- list_sec = isinstance (self .secondary_y , _types )
915
- has_sec = list_sec and len (self .secondary_y ) > 0
916
- all_sec = list_sec and len (self .secondary_y ) == self .nseries
917
-
918
- if (sec_true or has_sec ) and not hasattr (ax , 'right_ax' ):
912
+ if hasattr (ax , 'right_ax' ):
913
+ return ax .right_ax
914
+ else :
919
915
orig_ax , new_ax = ax , ax .twinx ()
920
916
new_ax ._get_lines .color_cycle = orig_ax ._get_lines .color_cycle
921
917
@@ -924,38 +920,25 @@ def _maybe_right_yaxis(self, ax):
924
920
925
921
if len (orig_ax .get_lines ()) == 0 : # no data on left y
926
922
orig_ax .get_yaxis ().set_visible (False )
927
-
928
- if len (new_ax .get_lines ()) == 0 :
929
- new_ax .get_yaxis ().set_visible (False )
930
-
931
- if sec_true or all_sec :
932
- ax = new_ax
933
- else :
934
- ax .get_yaxis ().set_visible (True )
935
-
936
- return ax
923
+ return new_ax
937
924
938
925
def _setup_subplots (self ):
939
926
if self .subplots :
940
927
nrows , ncols = self ._get_layout ()
941
928
fig , axes = _subplots (nrows = nrows , ncols = ncols ,
942
929
sharex = self .sharex , sharey = self .sharey ,
943
- figsize = self .figsize , ax = self .ax ,
944
- secondary_y = self .secondary_y ,
945
- data = self .data )
930
+ figsize = self .figsize , ax = self .ax )
946
931
if not com .is_list_like (axes ):
947
932
axes = np .array ([axes ])
948
933
else :
949
934
if self .ax is None :
950
935
fig = self .plt .figure (figsize = self .figsize )
951
936
ax = fig .add_subplot (111 )
952
- ax = self ._maybe_right_yaxis (ax )
953
937
else :
954
938
fig = self .ax .get_figure ()
955
939
if self .figsize is not None :
956
940
fig .set_size_inches (self .figsize )
957
- ax = self ._maybe_right_yaxis (self .ax )
958
-
941
+ ax = self .ax
959
942
axes = [ax ]
960
943
961
944
if self .logx or self .loglog :
@@ -1182,14 +1165,21 @@ def _get_ax(self, i):
1182
1165
# get the twinx ax if appropriate
1183
1166
if self .subplots :
1184
1167
ax = self .axes [i ]
1168
+
1169
+ if self .on_right (i ):
1170
+ ax = self ._maybe_right_yaxis (ax )
1171
+ self .axes [i ] = ax
1185
1172
else :
1186
1173
ax = self .axes [0 ]
1187
1174
1188
- if self .on_right (i ):
1189
- if hasattr (ax , 'right_ax' ):
1190
- ax = ax .right_ax
1191
- elif hasattr (ax , 'left_ax' ):
1192
- ax = ax .left_ax
1175
+ if self .on_right (i ):
1176
+ ax = self ._maybe_right_yaxis (ax )
1177
+
1178
+ sec_true = isinstance (self .secondary_y , bool ) and self .secondary_y
1179
+ all_sec = (com .is_list_like (self .secondary_y ) and
1180
+ len (self .secondary_y ) == self .nseries )
1181
+ if sec_true or all_sec :
1182
+ self .axes [0 ] = ax
1193
1183
1194
1184
ax .get_yaxis ().set_visible (True )
1195
1185
return ax
@@ -1550,8 +1540,6 @@ def _make_plot(self):
1550
1540
data = self ._maybe_convert_index (self .data )
1551
1541
self ._make_ts_plot (data )
1552
1542
else :
1553
- from pandas .core .frame import DataFrame
1554
- lines = []
1555
1543
x = self ._get_xticks (convert_period = True )
1556
1544
1557
1545
plotf = self ._get_plot_function ()
@@ -1563,8 +1551,6 @@ def _make_plot(self):
1563
1551
kwds = self .kwds .copy ()
1564
1552
self ._maybe_add_color (colors , kwds , style , i )
1565
1553
1566
- lines += _get_all_lines (ax )
1567
-
1568
1554
errors = self ._get_errorbars (label = label , index = i )
1569
1555
kwds = dict (kwds , ** errors )
1570
1556
@@ -1588,15 +1574,13 @@ def _make_plot(self):
1588
1574
newlines = plotf (* args , ** kwds )
1589
1575
self ._add_legend_handle (newlines [0 ], label , index = i )
1590
1576
1591
- lines .append (newlines [0 ])
1592
-
1593
1577
if self .stacked and not self .subplots :
1594
1578
if (y >= 0 ).all ():
1595
1579
self ._pos_prior += y
1596
1580
elif (y <= 0 ).all ():
1597
1581
self ._neg_prior += y
1598
1582
1599
- if self . _is_datetype ():
1583
+ lines = _get_all_lines ( ax )
1600
1584
left , right = _get_xlim (lines )
1601
1585
ax .set_xlim (left , right )
1602
1586
@@ -2253,14 +2237,7 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
2253
2237
import matplotlib .pyplot as plt
2254
2238
if ax is None and len (plt .get_fignums ()) > 0 :
2255
2239
ax = _gca ()
2256
- if ax .get_yaxis ().get_ticks_position ().strip ().lower () == 'right' :
2257
- fig = _gcf ()
2258
- axes = fig .get_axes ()
2259
- for i in reversed (range (len (axes ))):
2260
- ax = axes [i ]
2261
- ypos = ax .get_yaxis ().get_ticks_position ().strip ().lower ()
2262
- if ypos == 'left' :
2263
- break
2240
+ ax = getattr (ax , 'left_ax' , ax )
2264
2241
2265
2242
# is there harm in this?
2266
2243
if label is None :
@@ -2884,8 +2861,7 @@ def _get_layout(nplots, layout=None):
2884
2861
2885
2862
2886
2863
def _subplots (nrows = 1 , ncols = 1 , naxes = None , sharex = False , sharey = False , squeeze = True ,
2887
- subplot_kw = None , ax = None , secondary_y = False , data = None ,
2888
- ** fig_kw ):
2864
+ subplot_kw = None , ax = None , ** fig_kw ):
2889
2865
"""Create a figure with a set of subplots already made.
2890
2866
2891
2867
This utility wrapper makes it convenient to create common layouts of
@@ -2926,12 +2902,6 @@ def _subplots(nrows=1, ncols=1, naxes=None, sharex=False, sharey=False, squeeze=
2926
2902
2927
2903
ax : Matplotlib axis object, optional
2928
2904
2929
- secondary_y : boolean or sequence of ints, default False
2930
- If True then y-axis will be on the right
2931
-
2932
- data : DataFrame, optional
2933
- If secondary_y is a sequence, data is used to select columns.
2934
-
2935
2905
fig_kw : Other keyword arguments to be passed to the figure() call.
2936
2906
Note that all keywords not recognized above will be
2937
2907
automatically included here.
@@ -2996,22 +2966,8 @@ def _subplots(nrows=1, ncols=1, naxes=None, sharex=False, sharey=False, squeeze=
2996
2966
2997
2967
axarr = np .empty (nplots , dtype = object )
2998
2968
2999
- def on_right (i ):
3000
- if isinstance (secondary_y , bool ):
3001
- return secondary_y
3002
- if isinstance (data , DataFrame ):
3003
- return data .columns [i ] in secondary_y
3004
-
3005
2969
# Create first subplot separately, so we can share it if requested
3006
2970
ax0 = fig .add_subplot (nrows , ncols , 1 , ** subplot_kw )
3007
- if on_right (0 ):
3008
- orig_ax = ax0
3009
- ax0 = ax0 .twinx ()
3010
- ax0 ._get_lines .color_cycle = orig_ax ._get_lines .color_cycle
3011
-
3012
- orig_ax .get_yaxis ().set_visible (False )
3013
- orig_ax .right_ax = ax0
3014
- ax0 .left_ax = orig_ax
3015
2971
3016
2972
if sharex :
3017
2973
subplot_kw ['sharex' ] = ax0
@@ -3023,12 +2979,6 @@ def on_right(i):
3023
2979
# convention.
3024
2980
for i in range (1 , nplots ):
3025
2981
ax = fig .add_subplot (nrows , ncols , i + 1 , ** subplot_kw )
3026
- if on_right (i ):
3027
- orig_ax = ax
3028
- ax = ax .twinx ()
3029
- ax ._get_lines .color_cycle = orig_ax ._get_lines .color_cycle
3030
-
3031
- orig_ax .get_yaxis ().set_visible (False )
3032
2982
axarr [i ] = ax
3033
2983
3034
2984
if nplots > 1 :
0 commit comments