ImportError: No module named matplotlib.pyplot

This error message occurs when the matplotlib.pyplot module is not installed or not imported properly in your Python environment. To fix this issue, you can install the matplotlib package using pip by running the following command in your command prompt or terminal:

pip install matplotlib

Watch a course Python - The Practical Guide

Then, you can import the pyplot module in your Python script by adding the following line at the beginning of your code:

import matplotlib.pyplot as plt

This imports the pyplot module from the matplotlib package and assigns it the alias plt for convenience. Once imported you can use plt to draw the plots.

import matplotlib.pyplot as plt

x = [1,2,3,4,5]
y = [5,7,3,9,10]
plt.plot(x,y)
plt.show()

This is a basic example of a line plot using the pyplot module.