AttributeError: module 'matplotlib' has no attribute 'bar'
in
The Complete Data Visualization Course with Python, R, Tableau, and Excel
/
Bar Chart - Python - How to Create a Bar Chart
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)
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
Thank you alot, it works now