Skip to content

Instantly share code, notes, and snippets.

@thoppe
Created April 9, 2020 16:49
Show Gist options
  • Save thoppe/f9674da5e2b7191ecd7bc2a6aafd39da to your computer and use it in GitHub Desktop.
Save thoppe/f9674da5e2b7191ecd7bc2a6aafd39da to your computer and use it in GitHub Desktop.
# Removing top tick marks (and other props) when using shared axes
# For more control, see
# https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.tick_params.html
import pylab as plt
import numpy as np
# Sample data
X = np.linspace(0, 1, 100)
R = np.random.uniform(size=100)
Y = X ** 2
# Create some subplots and get the axes
fig, ax = plt.subplots(2, 2, sharex=True)
ax = ax.ravel()
# Plot example data, note that X goes from [0, 1] on some plots
# and [1, 2] on others
ax[0].plot(X, X ** 2 + R)
ax[1].plot(X + 1, R)
ax[2].plot(X, X + R)
ax[3].plot(X, X ** 1.5 + R)
# Turn off top ticks
ax[0].tick_params(axis="x", width=0)
ax[1].tick_params(axis="x", width=0)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment