Reputation: 11
I am trying to set max value for the Y axis in my plot. I am using matplotlib.pyplot. I know how to set it to a certain value using plt.ylim. However, what I am trying to do is a bit more involved. I am trying to set the max Y axis to 5% more than the maximum Y value in the data. I am doing this so that I can see the outliers better.
Thanks in Advance.
Upvotes: 0
Views: 20206
Reputation: 12234
It is usually best to add some example code showing what you have tried (even if it doesn't work). People will then tailor their answers to make more sense.
In your case here is an example of how I would do it:
import matplotlib.pyplot as plt
import numpy as np
# Make some fake data to see if it works
x = np.linspace(0, 7, 100)
y = np.sin(x)
plt.plot(x, y)
# Get the y limits
ymin, ymax = min(y), max(y)
# Set the y limits making the maximum 5% greater
plt.ylim(ymin, 1.05 * ymax)
plt.show()
Upvotes: 8