Gerrie
Gerrie

Reputation: 806

How to set the starting position of the grid line?

I want to generate a grid line. But I don't like the grid lines start from 0.

miloc = plt.MultipleLocator(1)
ax.xaxis.grid(True, which='minor')

This will generate grid lines at 0,1,2,3,4.... . But I want to generate grid lines at 0.5, 1.5, 2.5, 3.5? is there any method? Thank you

Upvotes: 0

Views: 116

Answers (1)

wasif
wasif

Reputation: 15478

Use AutoMinorLocator:

from matplotlib.ticker import AutoMinorLocator

# Rest of the code

minor_locator = AutoMinorLocator(2)
ax.xaxis.set_minor_locator(minor_locator)
plt.grid(which='minor')

Upvotes: 1

Related Questions