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.
            Asked
            
        
        
            Active
            
        
            Viewed 2,014 times
        
    1 Answers
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
 
- 
                    I gave just an an example with values. I don't know the values in advance. – MrT77 Feb 25 '21 at 16:47
 - 
                    1plt.ylim(-1*max(abs(data)) * 1.1, max(abs(data)) * 1.1) ? – Correy Koshnick Feb 25 '21 at 16:51