Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'matplotlib' has no attribute 'plot'

Tags:

python

I am using python 3.6 and a learner. Below is a simple code of a sin wave.

import matplotlib.pyplot as plt 
import numpy as np 

x = np.linspace(-10 , 10, 100)
y = np.sin(x) 
plt.plot(x, y, marker="x")

I am receiving the error "AttributeError: module 'matplotlib' has no attribute 'plot'" Any help would be appreciated.

like image 845
X10nD Avatar asked Nov 16 '17 08:11

X10nD


People also ask

Has no attribute plot?

It means that there is an issue with syntax or we say that there is a syntax error. Solution: This error was raised in the above example because the syntax we used to import the matplotlib library was incorrect.

Why does matplotlib say no module?

Conclusion # The Python "ModuleNotFoundError: No module named 'matplotlib'" occurs when we forget to install the matplotlib module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install matplotlib command.

How do I run matplotlib in Jupyter?

Install Matplotlib Make sure you first have Jupyter notebook installed, then we can add Matplotlib to our virtual environment. To do so, navigate to the command prompt and type pip install matplotlib. Now launch your Jupyter notebook by simply typing jupyter notebook at the command prompt.

What does module ‘Matplotlib’ has no attribute ‘plot’ mean?

AttributeError: module 'matplotlib' has no attribute 'plot' When we run the above code, we will get module ‘matplotlib’ has no attribute ‘plot’ error. The AttributeError is because we have wrongly imported the matplotlib in your code. We get the error typically when we import the matplotlib library like this

Why is Matplotlib not showing up in my system?

Also, check the detailed tutorial on How to install matplotlib python If matplotlib is successfully installed in your system, but you still have an Attribute Error: module ‘matplotlib’ has no attribute ‘plot’. It means that there is an issue with syntax or we say that there is a syntax error.

Why do I receive an error when importing the Matplotlib library?

We receive an error because we used the wrong line of code to import the matplotlib library. To fix this error, we simply need to use the correct code to import the matplotlib library:

How to fix “no module named Matplotlib” error in Python?

You will get the version of the matplotlib package installed in your system, otherwise, you will get the ImportError: No module named matplotlib error. The solution for the above is very simple. You have to install the Matplotlib python package in your system. Use the below pip command to install it.


2 Answers

Have you installed matplotlib properly? I added an extra line to your code to show the plot. This code works properly in Visual Studio after installing the matplotlib library.

import matplotlib.pyplot as plt 
import numpy as np 

x = np.linspace(-10 , 10, 100)
y = np.sin(x) 
plt.plot(x, y, marker="x")
plt.show()
like image 153
Mark Schuurman Avatar answered Sep 20 '22 13:09

Mark Schuurman


Try this simple step.

use pyplot using below import statement when importing matplotlib library.

import matplotlib.pyplot as plt

like image 22
Pasindu Perera Avatar answered Sep 21 '22 13:09

Pasindu Perera