Home > front end >  How to set our own yticks on a graph?
How to set our own yticks on a graph?

Time:12-17

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.

CodePudding user response:

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)

  • Related