Skip to content

Instantly share code, notes, and snippets.

@gauden
Created November 15, 2015 11:11
Show Gist options
  • Save gauden/c8bee41a32c8196ee5b1 to your computer and use it in GitHub Desktop.
Save gauden/c8bee41a32c8196ee5b1 to your computer and use it in GitHub Desktop.
Convenience function to pad the axes in matplotlib
def pad_axis(ax, pct=2.0):
for dim in ('x', 'y'):
getter = ax.get_xlim if dim =='x' else ax.get_ylim
setter = ax.set_xlim if dim =='x' else ax.set_ylim
lo, hi = getter()
pad = (hi-lo) / 100.0 * pct
setter(lo-pad, hi+pad)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment