From 770cdaf5b916fdbf2ae0e9eb9abf62039e4d0fe8 Mon Sep 17 00:00:00 2001 From: Fabrice Silva Date: Fri, 1 Feb 2013 21:04:11 +0100 Subject: [PATCH 1/2] Allow sharing axis with axes from other figure. --- lib/matplotlib/pyplot.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 66930db40743..0c0c8b1ce691 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -820,10 +820,12 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, *ncols* : int Number of columns of the subplot grid. Defaults to 1. - *sharex* : string or bool + *sharex* : axes instance, string or bool If *True*, the X axis will be shared amongst all subplots. If *True* and you have multiple rows, the x tick labels on all but - the last row of plots will have visible set to *False* + the last row of plots will have visible set to *False*. + If an axes instance, same as *True* and the X axis is also shared + with the X axis of the provided axes instance. If a string must be one of "row", "col", "all", or "none". "all" has the same effect as *True*, "none" has the same effect as *False*. @@ -831,10 +833,12 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, If "col", each subplot column will share a X axis and the x tick labels on all but the last row will have visible set to *False*. - *sharey* : string or bool + *sharey* : axes instance, string or bool If *True*, the Y axis will be shared amongst all subplots. If *True* and you have multiple columns, the y tick labels on all but - the first column of plots will have visible set to *False* + the first column of plots will have visible set to *False*. + If an axes instance, same as *True* and the Y axis is also shared + with the Y axis of the provided axes instance. If a string must be one of "row", "col", "all", or "none". "all" has the same effect as *True*, "none" has the same effect as *False*. @@ -910,6 +914,8 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, # same as plt.subplots(2, 2, sharex=True, sharey=True) """ + if subplot_kw is None: + subplot_kw = {} # for backwards compatibility if isinstance(sharex, bool): if sharex: @@ -921,6 +927,13 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, sharey = "all" else: sharey = "none" + if isinstance(sharex, Axes): + subplot_kw['sharex'] = sharex + sharex = "all" + if isinstance(sharex, Axes): + subplot_kw['sharey'] = sharey + sharey = "all" + share_values = ["all", "row", "col", "none"] if sharex not in share_values: # 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, if sharey not in share_values: raise ValueError("sharey [%s] must be one of %s" % \ (sharey, share_values)) - if subplot_kw is None: - subplot_kw = {} fig = figure(**fig_kw) From 5a3f4312bbe8674752cbba93ce11dd2ae3c4b704 Mon Sep 17 00:00:00 2001 From: Fabrice Silva Date: Fri, 1 Feb 2013 21:36:29 +0100 Subject: [PATCH 2/2] Fix sharex->sharey. --- lib/matplotlib/pyplot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 0c0c8b1ce691..c91efbbf9b96 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -930,7 +930,7 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, if isinstance(sharex, Axes): subplot_kw['sharex'] = sharex sharex = "all" - if isinstance(sharex, Axes): + if isinstance(sharey, Axes): subplot_kw['sharey'] = sharey sharey = "all"