Created
November 6, 2021 00:01
-
-
Save m-tmatma/d132483ddc96a1e2411f4c98d4d17733 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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