From 0e057cde99cc0825559ac62dee0d266077fac353 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 7 Mar 2017 20:50:46 +0000 Subject: [PATCH 1/5] MEP12 and simplify ganged_plots example --- examples/pylab_examples/ganged_plots.py | 49 +++++++++++-------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/examples/pylab_examples/ganged_plots.py b/examples/pylab_examples/ganged_plots.py index 9d14a522c546..592b09eb17f9 100644 --- a/examples/pylab_examples/ganged_plots.py +++ b/examples/pylab_examples/ganged_plots.py @@ -1,8 +1,12 @@ """ +========================== +Creating adjacent subplots +========================== + To create plots that share a common axes (visually) you can set the -hspace between the subplots close to zero (do not use zero itself). -Normally you'll want to turn off the tick labels on all but one of the -axes. +hspace between the subplots close to zero (do not use zero itself). Passing +sharex=True when creating the subplots will automatically turn of all x ticks +and labels apart from on the bottom axis. In this example the plots share a common xaxis but you can follow the same logic to supply a common y axis. @@ -12,34 +16,25 @@ t = np.arange(0.0, 2.0, 0.01) -s1 = np.sin(2*np.pi*t) +s1 = np.sin(2 * np.pi * t) s2 = np.exp(-t) -s3 = s1*s2 - -# axes rect in relative 0,1 coords left, bottom, width, height. Turn -# off xtick labels on all but the lower plot - - -f = plt.figure() -plt.subplots_adjust(hspace=0.001) - +s3 = s1 * s2 -ax1 = plt.subplot(311) -ax1.plot(t, s1) -plt.yticks(np.arange(-0.9, 1.0, 0.4)) -plt.ylim(-1, 1) +fig, axs = plt.subplots(3, 1, sharex=True) +# Remove horizontal space between axes +fig.subplots_adjust(hspace=0.001) -ax2 = plt.subplot(312, sharex=ax1) -ax2.plot(t, s2) -plt.yticks(np.arange(0.1, 1.0, 0.2)) -plt.ylim(0, 1) +# Plot each graph, and manually set the y tick values +axs[0].plot(t, s1) +axs[0].set_yticks(np.arange(-0.9, 1.0, 0.4)) +axs[0].set_ylim(-1, 1) -ax3 = plt.subplot(313, sharex=ax1) -ax3.plot(t, s3) -plt.yticks(np.arange(-0.9, 1.0, 0.4)) -plt.ylim(-1, 1) +axs[1].plot(t, s2) +axs[1].set_yticks(np.arange(0.1, 1.0, 0.2)) +axs[1].set_ylim(0, 1) -xticklabels = ax1.get_xticklabels() + ax2.get_xticklabels() -plt.setp(xticklabels, visible=False) +axs[2].plot(t, s3) +axs[2].set_yticks(np.arange(-0.9, 1.0, 0.4)) +axs[2].set_ylim(-1, 1) plt.show() From 64c5aa22f44b9111382c432b5ff7c73b86c13bea Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 7 Mar 2017 20:51:20 +0000 Subject: [PATCH 2/5] Move ganged plots example --- .../{pylab_examples => subplots_axes_and_figures}/ganged_plots.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{pylab_examples => subplots_axes_and_figures}/ganged_plots.py (100%) diff --git a/examples/pylab_examples/ganged_plots.py b/examples/subplots_axes_and_figures/ganged_plots.py similarity index 100% rename from examples/pylab_examples/ganged_plots.py rename to examples/subplots_axes_and_figures/ganged_plots.py From 76b34e1bae5bedadd049adbaf719b7529ee01078 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 8 Mar 2017 09:28:41 +0000 Subject: [PATCH 3/5] Set subplot spacing to zero --- examples/subplots_axes_and_figures/ganged_plots.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/subplots_axes_and_figures/ganged_plots.py b/examples/subplots_axes_and_figures/ganged_plots.py index 592b09eb17f9..d5702865c6b1 100644 --- a/examples/subplots_axes_and_figures/ganged_plots.py +++ b/examples/subplots_axes_and_figures/ganged_plots.py @@ -4,9 +4,9 @@ ========================== To create plots that share a common axes (visually) you can set the -hspace between the subplots close to zero (do not use zero itself). Passing -sharex=True when creating the subplots will automatically turn of all x ticks -and labels apart from on the bottom axis. +hspace between the subplots to zero. Passing sharex=True when creating the +subplots will automatically turn of all x ticks and labels apart from on the +bottom axis. In this example the plots share a common xaxis but you can follow the same logic to supply a common y axis. @@ -22,7 +22,7 @@ fig, axs = plt.subplots(3, 1, sharex=True) # Remove horizontal space between axes -fig.subplots_adjust(hspace=0.001) +fig.subplots_adjust(hspace=0) # Plot each graph, and manually set the y tick values axs[0].plot(t, s1) From 0e5f7eac54f7ebc781c08270dacaf9b24f8356e8 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 8 Mar 2017 17:17:44 +0000 Subject: [PATCH 4/5] Fix example description phrasing --- examples/subplots_axes_and_figures/ganged_plots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/subplots_axes_and_figures/ganged_plots.py b/examples/subplots_axes_and_figures/ganged_plots.py index d5702865c6b1..c354cec3c826 100644 --- a/examples/subplots_axes_and_figures/ganged_plots.py +++ b/examples/subplots_axes_and_figures/ganged_plots.py @@ -5,7 +5,7 @@ To create plots that share a common axes (visually) you can set the hspace between the subplots to zero. Passing sharex=True when creating the -subplots will automatically turn of all x ticks and labels apart from on the +subplots will automatically turn off all x ticks and labels except those on the bottom axis. In this example the plots share a common xaxis but you can follow the From 8b5391c219e08e0d359b413aaef2c99a2e6f16ad Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 13 Mar 2017 10:04:35 +0000 Subject: [PATCH 5/5] Small header comment fixes --- examples/subplots_axes_and_figures/ganged_plots.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/subplots_axes_and_figures/ganged_plots.py b/examples/subplots_axes_and_figures/ganged_plots.py index c354cec3c826..4014dabdf046 100644 --- a/examples/subplots_axes_and_figures/ganged_plots.py +++ b/examples/subplots_axes_and_figures/ganged_plots.py @@ -3,13 +3,13 @@ Creating adjacent subplots ========================== -To create plots that share a common axes (visually) you can set the -hspace between the subplots to zero. Passing sharex=True when creating the -subplots will automatically turn off all x ticks and labels except those on the -bottom axis. +To create plots that share a common axis (visually) you can set the hspace +between the subplots to zero. Passing sharex=True when creating the subplots +will automatically turn off all x ticks and labels except those on the bottom +axis. -In this example the plots share a common xaxis but you can follow the -same logic to supply a common y axis. +In this example the plots share a common x axis but you can follow the same +logic to supply a common y axis. """ import matplotlib.pyplot as plt import numpy as np