1

Is there any option to force that the y-axis limits will always be symmetric around 0, independently of what is being drawn? E.g., my plot contents true limits are +1 and -0.8 (just an example, as I don't know the values in advance), but I would like matplotlib to force this to +1 and -1.

MrT77
  • 811
  • 6
  • 25

1 Answers1

4

You can set limits of the y-axis manually:

plt.ylim(-1, 1)

If you want to adjust the limits automatically then you can try this:

plt.plot([1, 2, 3], [-1, 7, -4])

# get y-axis limits of the plot
low, high = plt.ylim()
# find the new limits
bound = max(abs(low), abs(high))
# set new limits
plt.ylim(-bound, bound)
bb1
  • 7,174
  • 2
  • 8
  • 23