Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mep12 on ganged_plots.py #5041

Merged
merged 1 commit into from
Sep 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 18 additions & 18 deletions examples/pylab_examples/ganged_plots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
"""
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).
Expand All @@ -8,38 +7,39 @@
In this example the plots share a common xaxis but you can follow the
same logic to supply a common y axis.
"""
from pylab import *
import matplotlib.pyplot as plt
import numpy as np

t = arange(0.0, 2.0, 0.01)
t = np.arange(0.0, 2.0, 0.01)

s1 = sin(2*pi*t)
s2 = exp(-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 = figure()
subplots_adjust(hspace=0.001)
f = plt.figure()
plt.subplots_adjust(hspace=0.001)


ax1 = subplot(311)
ax1 = plt.subplot(311)
ax1.plot(t, s1)
yticks(arange(-0.9, 1.0, 0.4))
ylim(-1, 1)
plt.yticks(np.arange(-0.9, 1.0, 0.4))
plt.ylim(-1, 1)

ax2 = subplot(312, sharex=ax1)
ax2 = plt.subplot(312, sharex=ax1)
ax2.plot(t, s2)
yticks(arange(0.1, 1.0, 0.2))
ylim(0, 1)
plt.yticks(np.arange(0.1, 1.0, 0.2))
plt.ylim(0, 1)

ax3 = subplot(313, sharex=ax1)
ax3 = plt.subplot(313, sharex=ax1)
ax3.plot(t, s3)
yticks(arange(-0.9, 1.0, 0.4))
ylim(-1, 1)
plt.yticks(np.arange(-0.9, 1.0, 0.4))
plt.ylim(-1, 1)

xticklabels = ax1.get_xticklabels() + ax2.get_xticklabels()
setp(xticklabels, visible=False)
plt.setp(xticklabels, visible=False)

show()
plt.show()