Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to shift up the y-axis in matplotplib so that zero starts from "higher up"?

I have a problem regarding the starting point of y-axis. My data has some values that are almost below zero, but i dont want my graph to show negative values. I want my y-axis values to start from zero. Can i shift up the y-axis, still starting from zero?

[Here is the current graph with plt.ylim(0, 1750)] 1

And here is without manually setting plt.ylim()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is my first question here. I hope the pictures are showing well.

Here is the desired outcome

>Solution :

You can place the ylim as slightly negative to "shift" your yaxis down slightly below zero. So long as you set a negative bottom ylim that is not as much as the intervals of you yticks, it shouldn’t populate a negative ytick on your graph,

With a slightly smaller bottom limit:

x = np.arange(0,1000)
y = np.arange(0,1000)

plt.plot(x,y)
plt.ylim(-50)

enter image description here

With a bottom ylim that equals the ytick interval:

x = np.arange(0,1000)
y = np.arange(0,1000)

plt.plot(x,y)
plt.ylim(-200)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading