Open Metric
Science, Fiction and Me

Today I Learned

Gridlines in Matplotlib

In matplotlib, enabling the gridlines would draw the lines according to the major and minor ticks. However, we need some gridlines at specified locations.

Adding a single gridline at location 10:

ax.axvline(10, linestyle='--', color='k')

When a bunch of lines are required, we define an array as the gridline locations then loop through the location to add in the grridlines.

gridlineslist = [1,2,3,4,5,6]

for gridline in gridlineslist:
    ax.axvline(gridline, linestyle='--', color='k')

A Random #TIL# for You


Most technical TILs will be updated at datumorphism.leima.is/til

By OctoMiao

Last updated