Matplotlib pyplot


Matplotlib pyplot

Pyplot is a module within the Matplotlib library that provides a collection of functions to create plots quickly and easily.

By using Pyplot, users can customize their visualizations with labels, titles, colors, and other stylistic elements, making it a convenient tool for creating basic to intermediate-level plots in Python.

Usually when using Matplotlib to draw plots, pyplot is imported as plt in the programs, as shown below.

import matplotlib.pyplot as plt

Now, let us use this in an example, program to draw a line plot.

Python Program

import matplotlib.pyplot as plt
import numpy as np

xpoints = np.array([10, 20, 30])
ypoints = np.array([50, 25, 100])

plt.plot(xpoints, ypoints)
plt.show()

Output