Skip to content

Instantly share code, notes, and snippets.

@dtoma
Created May 31, 2019 10:23
Show Gist options
  • Save dtoma/fbdb777a4ffda80906daf83fb401d1e2 to your computer and use it in GitHub Desktop.
Save dtoma/fbdb777a4ffda80906daf83fb401d1e2 to your computer and use it in GitHub Desktop.
Center a plot on y=0
data = pd.Series(...)
highest_point = abs(data.max())
lowest_point = abs(data.min())
max_y = max(highest_point, lowest_point)
# Expand to the nearest order of magnitude (throws if max_y==0)
max_y *= 10**int(math.log10(max_y))
data.plot(ylim=(-max_y, max_y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment