In this tutorial I will be walking you thorugh some of the basics when inserting gridline and tickets of a matplotlib graph.


Buy Me a Coffee? Your support is much appreciated!
PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn





Python Code

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

fig = plt.figure(figsize=(8, 6))
axes = plt.subplot(1, 1, 1)
axes.axis([0, 12, 0, 10])

# major ticks
axes.xaxis.set_major_locator(MultipleLocator(3.0))
axes.yaxis.set_major_locator(MultipleLocator(2.0))

# minor ticks
axes.xaxis.set_minor_locator(MultipleLocator(0.2))
axes.yaxis.set_minor_locator(MultipleLocator(0.2))

# major gridlines
axes.grid(which='major', axis='x', linewidth=1, linestyle='-', color='lime', alpha=0.5)
axes.grid(which='major', axis='y', linewidth=1, linestyle='-', color='green', alpha=0.5)

# minor gridlines
axes.grid(which='minor', axis='x', linewidth=1, linestyle='-', color='firebrick', alpha=0.5)
axes.grid(which='minor', axis='y', linewidth=1, linestyle='-', color='firebrick', alpha=0.5)

plt.show()