The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →The usual fix is to import pyplot, not the top-level matplotlib package:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [2, 4, 6])
plt.show()
plot is documented as matplotlib.pyplot.plot. If this import is already in place, check whether plt was reassigned or Python loaded a different module than the installed Matplotlib library.
Why this error occurs
The top-level matplotlib package and matplotlib.pyplot are different modules. The plotting function is documented under pyplot, where plot wraps the corresponding Axes.plot method. The official plot API accepts y values alone or x and y values.
This import binds the alias to the wrong module:
import matplotlib as plt
plt.plot([1, 2, 3], [2, 4, 6])
Here, plt refers to matplotlib, not matplotlib.pyplot, so calling plt.plot can raise the reported AttributeError. Use import matplotlib.pyplot as plt instead. The pyplot guide documents this interface and its role in simple plotting.
Recommended Free Tools
#1 Best Overall
Apply the direct fix
- Replace
import matplotlib as pltwithimport matplotlib.pyplot as plt. - Call
plt.plot(x, y), or pass only y values when the x positions can use their default sequence. - Use
plt.show()when you need to display the completed figure in an interactive context. It displays a figure; it does not create a missingplotattribute or fix the import.
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [2, 4, 6]
plt.plot(x, y)
plt.show()
If the corrected import still fails
Work through these checks before reinstalling Matplotlib. The error by itself does not establish that the installation is broken.
- Check the import and alias. Confirm the code imports
matplotlib.pyplot as pltand callsplt.plot(...). Search later in the script or notebook for assignments topltor another import that replaces that name. - Inspect the imported package location. Temporarily run
import matplotlib; print(matplotlib.__file__). The path should point to the Matplotlib installation in the environment running your code. If it points to a project file or directory namedmatplotlib, that local name may be shadowing the installed package. Rename the conflicting file or directory; remove stale bytecode or cache files if appropriate, then restart the Python process or notebook kernel. - Confirm the Python environment. Make sure the interpreter running the script or notebook is the same environment in which Matplotlib is installed. Installing it into a different environment will not change what the current interpreter imports.
- Only then investigate installation problems. If the import, module path, and interpreter all check out, investigate the installation in that environment. The error message alone does not establish a particular version threshold or prove a Matplotlib defect.
Choose pyplot or explicit Axes methods
For a quick or interactive plot, pyplot is concise and appropriate. For a more complex figure, Matplotlib recommends working with explicit Figure and Axes objects; this makes the target axes clear rather than relying on pyplot’s implicit state.
Rank #2
| Style | Example | When it fits |
|---|---|---|
| Pyplot | plt.plot(x, y) |
Concise plotting, especially for simple or interactive work. |
| Explicit object-oriented | fig, ax = plt.subplots(); ax.plot(x, y) |
Complex plots where explicit control of the Figure and Axes is useful. |
Both styles start with import matplotlib.pyplot as plt. In the object-oriented style, call plot on the Axes object returned by plt.subplots().
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




