Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MEP12 ganged example #8229

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

Merged
merged 5 commits into from
Mar 16, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
MEP12 and simplify ganged_plots example
  • Loading branch information
dstansby committed Mar 7, 2017
commit 0e057cde99cc0825559ac62dee0d266077fac353
49 changes: 22 additions & 27 deletions 49 examples/pylab_examples/ganged_plots.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.