Skip to content

Instantly share code, notes, and snippets.

@dmyersturnbull
Created May 5, 2020 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmyersturnbull/7fff6a1f9cad76bf8cb82772beb7cf8b to your computer and use it in GitHub Desktop.
Save dmyersturnbull/7fff6a1f9cad76bf8cb82772beb7cf8b to your computer and use it in GitHub Desktop.
Remove spines on a matplotlib figure.
from matplotlib.axes import Axes
@classmethod
def despine(cls, ax: Axes) -> Axes:
"""
Removes all spines and ticks on an Axes.
"""
ax.set_yticks([])
ax.set_yticks([])
ax.set_xticklabels([])
ax.set_yticklabels([])
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.get_xaxis().set_ticks([])
ax.get_yaxis().set_ticks([])
return ax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment