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

How to set our own yticks on a graph?

enter image description here

I want to increase the yticks upto 100. It is currently 80 but i want it to be 100.

plt.yticks(np.arange(0,100,10))

but this doesn’t work.

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

>Solution :

A couple of things:

  1. using pyplot isn’t recommended (but is still possible for the sake of backwards compatibility)
  2. setting the ticks or tick labels isn’t recommended as those solutions fall apart when the axes limits changes.

So the solution is to

  1. use the object-oriented interface
  2. set the locator and limits directly
from matplotlib import pyplot
from matplotlib import ticker

fig, ax = pyplot.subplots(figsize=(6, 4))
ax.bar(...)
# or df.plot.bar(..., ax=ax)
ax.yaxis.set_major_locator(ticker.MultipleLocator(10))
ax.set_ylim(bottom=0, top=100)

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