O'Reilly logo

Matplotlib for Python Developers by Allen Yu, Claire Chung, Aldrin Yim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Line plot

After importing matplotlib.pyplot as plt, we draw line plots with the plt.plot() command.

Here is a code snippet for a simple example of plotting the temperature of the week:

# Import the Matplotlib moduleimport matplotlib.pyplot as plt# Use a list to store the daily temperaturet = [22.2,22.3,22.5,21.8,22.5,23.4,22.8]# Plot the daily temperature t as a line plotplt.plot(t)# Show the plotplt.show()

After you run the code, the following plot will be displayed as the output in the notebook cell:

When a single parameter is parsed, the data values are assumed to be on the y axis, with the indices on the x axis.

Remember to conclude each ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required