Home > other >  How to set minor locator
How to set minor locator

Time:05-09

I am a beginner to matplotlib and came across a question about minor_locators. I tried looking it up but couldn't work out how to create them in my bar graph. Any help is greatly appreciated.

CodePudding user response:

The easiest way to set minor_locators is to use the AutoMinorLocator(). It gives you the generally most appropriate minor ticks without any hassles of setting them manually. Add all of this to the code of your regular graph and you should be good to go:

import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator

ax = plt.gca()
ax.yaxis.set_minor_locator(AutoMinorLocator())
ax.xaxis.set_minor_locator(AutoMinorLocator())

For more specific ticks, read up on the official documentation here

  • Related