Search icon CANCEL
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Matplotlib 2.x By Example

You're reading from  Matplotlib 2.x By Example

Product type Book
Published in Aug 2017
Publisher Packt
ISBN-13 9781788295260
Pages 334 pages
Edition 1st Edition
Languages
Authors (3):
Allen Yu Allen Yu
Profile icon Allen Yu
Claire Chung Claire Chung
Profile icon Claire Chung
Aldrin Yim Aldrin Yim
Profile icon Aldrin Yim
View More author details

Customizing grids, ticks, and axes


Lines of grids, ticks, and axes help us to visually locate and measure the data values. Their distribution and style determine whether they make good visual aids for the plot or clutter the figure. We will demonstrate the basic methods here.

Grids

Sometimes it may not be easy to tell the coordinates of any point in the plot. Grid lines extend from axis tick marks and help us estimate the value at a certain position.

Adding grids

Grids can be added by calling pyplot.grid(). By default, grid lines will be added at major tick marks. As in other line features, pyplot.grid() takes in parameters such as linewidth (lw), linestyle (ls), and color (c):

import numpy as np
import matplotlib.pyplot as plt

# Prepare 100 evenly spaced numbers from 0 to 200
evens = np.linspace(0,200,100)

# Plot a square curve
plt.plot(evens,evens**2,label = 'x^2')

# Adding grid lines
plt.grid()

plt.legend()
plt.show()

Here you see the default grid lines extending from axis ticks:

In the...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}