Python Matplotlib Library
Python Matplotlib Library
Let’s learn about the Python Matplotlib Library in this tutorial. The Python Matplotlib Library provides many interfaces and functionality for 2D graphics.
Python Matplotlib Library
Matplotlib is a high-quality plotting library that enables programmers to create 2D plots and graphs. We can use PyPlot to construct plots. PyPlot is a collection of methods within the Matplotlib library that allows users to construct plots easily.
Import PyPlot
To use PyPlot methods, we need to import it. We can import and use Pyplot in the following ways:
Syntax
The general syntax to import PyPlot is:
import matplotlib.pyplot as <alias>
In this alternative approach, we must issue every pyplot command
matplotlib.pyplot.<command>
Example
In this example, we will import the matplotlib module in the program.
# Line chart using PyPlot
# Python Tutorials – www.TestingDocs.com
import matplotlib.pyplot as pypt
# Define two lists
a=[12,25,37,49]
b=[210,43,650,187]
# Plotting the data
pypt.plot(a,b,’b’)
pypt.show()
Notice that we have provided pypt alias as the shorthand for matplotlib.pyplot. We can invoke PyPlot’s methods using the alias. For example, to plot the two lists, a and b, we can use the following plot command:
pypt.plot(a , b)
—
Python Tutorials
Python Tutorial on this website can be found at:
https://www.testingdocs.com/python-tutorials/
More information on Python is available at the official website: