Last answered:

03 Nov 2021

Posted on:

01 Nov 2021

0

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

Hi all
when i write this code and run it

plt.bar(x = df_used_cars["Brand"],
        height = df_used_cars["Cars Listings"])
plt.show()

I got this error

AttributeError                            Traceback (most recent call last)
<ipython-input-19-8febc10c5094> in <module>
----> 1 plt.bar(x = df_used_cars["Brand"],
      2         height = df_used_cars["Cars Listings"])
      3 plt.show()

AttributeError: module 'matplotlib' has no attribute 'bar'
2 answers ( 0 marked as helpful)
Instructor
Posted on:

02 Nov 2021

0

Hi Fathy,
thanks for reaching out! Could you go to the import section of the code and make sure you've used the pyplot module of matplotlib, as it is the one containing the bar function. So you need to import matplotlib.pyplot, like so:

import matplotlib.pyplot as plt

Alternatively, if that's not causing the issue, you can try to uninstall and unistall and then reinstall the matplotlib library using pip(from the Anaconda prompt).
Let me know if you encounter any other issues!

Best,
365 Eli

Posted on:

03 Nov 2021

0

Thank you alot, it works now

Submit an answer