Home > front end >  Why I get eror when I want to use plt.scatter?
Why I get eror when I want to use plt.scatter?

Time:12-19

I wanted to use the scatter function from matplotlib library on a database but I simply can not.

below is my code and the error:

import matplotlib as plt

y = df["price"]

x = df["engine-size"]

plt.scatter(x,y)

error: AttributeError: module 'matplotlib' has no attribute 'scatter'

CodePudding user response:

You must import matplotlib.pyplot as plt. See here for an example https://matplotlib.org/stable/gallery/shapes_and_collections/scatter.html#sphx-glr-gallery-shapes-and-collections-scatter-py

CodePudding user response:

Do your import this way;

from matplotlib import pyplot as plt

Then run your code again This should work

  • Related