@@ -909,13 +909,9 @@ def _args_adjust(self):
909909 pass
910910
911911 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 :
919915 orig_ax , new_ax = ax , ax .twinx ()
920916 new_ax ._get_lines .color_cycle = orig_ax ._get_lines .color_cycle
921917
@@ -924,38 +920,25 @@ def _maybe_right_yaxis(self, ax):
924920
925921 if len (orig_ax .get_lines ()) == 0 : # no data on left y
926922 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
937924
938925 def _setup_subplots (self ):
939926 if self .subplots :
940927 nrows , ncols = self ._get_layout ()
941928 fig , axes = _subplots (nrows = nrows , ncols = ncols ,
942929 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 )
946931 if not com .is_list_like (axes ):
947932 axes = np .array ([axes ])
948933 else :
949934 if self .ax is None :
950935 fig = self .plt .figure (figsize = self .figsize )
951936 ax = fig .add_subplot (111 )
952- ax = self ._maybe_right_yaxis (ax )
953937 else :
954938 fig = self .ax .get_figure ()
955939 if self .figsize is not None :
956940 fig .set_size_inches (self .figsize )
957- ax = self ._maybe_right_yaxis (self .ax )
958-
941+ ax = self .ax
959942 axes = [ax ]
960943
961944 if self .logx or self .loglog :
@@ -1182,14 +1165,21 @@ def _get_ax(self, i):
11821165 # get the twinx ax if appropriate
11831166 if self .subplots :
11841167 ax = self .axes [i ]
1168+
1169+ if self .on_right (i ):
1170+ ax = self ._maybe_right_yaxis (ax )
1171+ self .axes [i ] = ax
11851172 else :
11861173 ax = self .axes [0 ]
11871174
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
11931183
11941184 ax .get_yaxis ().set_visible (True )
11951185 return ax
@@ -1550,8 +1540,6 @@ def _make_plot(self):
15501540 data = self ._maybe_convert_index (self .data )
15511541 self ._make_ts_plot (data )
15521542 else :
1553- from pandas .core .frame import DataFrame
1554- lines = []
15551543 x = self ._get_xticks (convert_period = True )
15561544
15571545 plotf = self ._get_plot_function ()
@@ -1563,8 +1551,6 @@ def _make_plot(self):
15631551 kwds = self .kwds .copy ()
15641552 self ._maybe_add_color (colors , kwds , style , i )
15651553
1566- lines += _get_all_lines (ax )
1567-
15681554 errors = self ._get_errorbars (label = label , index = i )
15691555 kwds = dict (kwds , ** errors )
15701556
@@ -1588,15 +1574,13 @@ def _make_plot(self):
15881574 newlines = plotf (* args , ** kwds )
15891575 self ._add_legend_handle (newlines [0 ], label , index = i )
15901576
1591- lines .append (newlines [0 ])
1592-
15931577 if self .stacked and not self .subplots :
15941578 if (y >= 0 ).all ():
15951579 self ._pos_prior += y
15961580 elif (y <= 0 ).all ():
15971581 self ._neg_prior += y
15981582
1599- if self . _is_datetype ():
1583+ lines = _get_all_lines ( ax )
16001584 left , right = _get_xlim (lines )
16011585 ax .set_xlim (left , right )
16021586
@@ -2253,14 +2237,7 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
22532237 import matplotlib .pyplot as plt
22542238 if ax is None and len (plt .get_fignums ()) > 0 :
22552239 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 )
22642241
22652242 # is there harm in this?
22662243 if label is None :
@@ -2884,8 +2861,7 @@ def _get_layout(nplots, layout=None):
28842861
28852862
28862863def _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 ):
28892865 """Create a figure with a set of subplots already made.
28902866
28912867 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=
29262902
29272903 ax : Matplotlib axis object, optional
29282904
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-
29352905 fig_kw : Other keyword arguments to be passed to the figure() call.
29362906 Note that all keywords not recognized above will be
29372907 automatically included here.
@@ -2996,22 +2966,8 @@ def _subplots(nrows=1, ncols=1, naxes=None, sharex=False, sharey=False, squeeze=
29962966
29972967 axarr = np .empty (nplots , dtype = object )
29982968
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-
30052969 # Create first subplot separately, so we can share it if requested
30062970 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
30152971
30162972 if sharex :
30172973 subplot_kw ['sharex' ] = ax0
@@ -3023,12 +2979,6 @@ def on_right(i):
30232979 # convention.
30242980 for i in range (1 , nplots ):
30252981 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 )
30322982 axarr [i ] = ax
30332983
30342984 if nplots > 1 :
0 commit comments