@@ -820,21 +820,25 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
820
820
*ncols* : int
821
821
Number of columns of the subplot grid. Defaults to 1.
822
822
823
- *sharex* : string or bool
823
+ *sharex* : axes instance, string or bool
824
824
If *True*, the X axis will be shared amongst all subplots. If
825
825
*True* and you have multiple rows, the x tick labels on all but
826
- the last row of plots will have visible set to *False*
826
+ the last row of plots will have visible set to *False*.
827
+ If an axes instance, same as *True* and the X axis is also shared
828
+ with the X axis of the provided axes instance.
827
829
If a string must be one of "row", "col", "all", or "none".
828
830
"all" has the same effect as *True*, "none" has the same effect
829
831
as *False*.
830
832
If "row", each subplot row will share a X axis.
831
833
If "col", each subplot column will share a X axis and the x tick
832
834
labels on all but the last row will have visible set to *False*.
833
835
834
- *sharey* : string or bool
836
+ *sharey* : axes instance, string or bool
835
837
If *True*, the Y axis will be shared amongst all subplots. If
836
838
*True* and you have multiple columns, the y tick labels on all but
837
- the first column of plots will have visible set to *False*
839
+ the first column of plots will have visible set to *False*.
840
+ If an axes instance, same as *True* and the Y axis is also shared
841
+ with the Y axis of the provided axes instance.
838
842
If a string must be one of "row", "col", "all", or "none".
839
843
"all" has the same effect as *True*, "none" has the same effect
840
844
as *False*.
@@ -910,6 +914,8 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
910
914
# same as
911
915
plt.subplots(2, 2, sharex=True, sharey=True)
912
916
"""
917
+ if subplot_kw is None :
918
+ subplot_kw = {}
913
919
# for backwards compatibility
914
920
if isinstance (sharex , bool ):
915
921
if sharex :
@@ -921,6 +927,13 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
921
927
sharey = "all"
922
928
else :
923
929
sharey = "none"
930
+ if isinstance (sharex , Axes ):
931
+ subplot_kw ['sharex' ] = sharex
932
+ sharex = "all"
933
+ if isinstance (sharex , Axes ):
934
+ subplot_kw ['sharey' ] = sharey
935
+ sharey = "all"
936
+
924
937
share_values = ["all" , "row" , "col" , "none" ]
925
938
if sharex not in share_values :
926
939
# This check was added because it is very easy to type subplots(1, 2, 1)
@@ -937,8 +950,6 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
937
950
if sharey not in share_values :
938
951
raise ValueError ("sharey [%s] must be one of %s" % \
939
952
(sharey , share_values ))
940
- if subplot_kw is None :
941
- subplot_kw = {}
942
953
943
954
fig = figure (** fig_kw )
944
955
0 commit comments