Skip to content

Instantly share code, notes, and snippets.

@m-tmatma
Created November 6, 2021 00:01
Show Gist options
  • Save m-tmatma/d132483ddc96a1e2411f4c98d4d17733 to your computer and use it in GitHub Desktop.
Save m-tmatma/d132483ddc96a1e2411f4c98d4d17733 to your computer and use it in GitHub Desktop.
# https://stackoverflow.com/questions/24943991/change-grid-interval-and-specify-tick-labels-in-matplotlib
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
# Major ticks every 20, minor ticks every 5
major_ticks = np.arange(0, 101, 20)
minor_ticks = np.arange(0, 101, 5)
ax.set_xticks(major_ticks)
ax.set_xticks(minor_ticks, minor=True)
ax.set_yticks(major_ticks)
ax.set_yticks(minor_ticks, minor=True)
# And a corresponding grid
ax.grid(which='both')
# Or if you want different settings for the grids:
ax.grid(which='minor', alpha=0.1)
ax.grid(which='major', alpha=0.7)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment