If you’ve ever tried to create 3D plots using Matplotlib in Python, you might have encountered the frustrating error message: “unknown projection ‘3d’”. I’ve been there myself, and as someone who’s been coding in Python for over a decade, I want to share simple, practical ways to solve this issue so you can get your 3D visualizations up and running smoothly.
This error usually pops up when Matplotlib doesn’t recognize the '3d' projection, which is essential for 3D plotting. The good news is, fixing it is easy once you know what to check. In this guide, I’ll walk you through the causes and multiple solutions based on firsthand experience, so you can quickly get past this hurdle.
Why Does the “Unknown Projection ‘3d'” Error Occur?
When you try to create a 3D plot in Matplotlib, you typically use code like this:
from matplotlib import pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')If Matplotlib isn’t properly set up to handle 3D projections, it throws the unknown projection ‘3d’ error.
The root cause is that the mpl_toolkits.mplot3d module, which enables 3D plotting in Matplotlib, is either not imported or not installed correctly.
Check out Matplotlib tight_layout
Methods to Fix the Matplotlib Unknown Projection ‘3d’ Error in Python
Now, I will explain to you the methods to fix the Matplotlib’ unknown projection ‘3d’ error in Python.
1: Import the mpl_toolkits.mplot3d Module Explicitly
One of the simplest ways to fix this is to ensure you import the 3D toolkit explicitly in your script:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.show()You can refer to the screenshot below to see the output

Even if you don’t directly use Axes3D, importing it registers the 3D projection with Matplotlib. This import is often overlooked but essential.
Read Python Matplotlib tick_params
2: Check Your Matplotlib Installation and Version
Sometimes this error occurs because your Matplotlib installation is outdated or corrupted.
To check your Matplotlib version, run:
import matplotlib
print(matplotlib.__version__)You can refer to the screenshot below to see the output

3D plotting support has been stable for many versions, but I recommend using at least version 3.1.0 or later. If your version is older, upgrade it using pip:
pip install --upgrade matplotlibOn some systems, especially Windows or macOS, if you installed Matplotlib via a package manager or Anaconda, ensure the installation is complete and not missing dependencies.
Check out Matplotlib x-axis Label
3: Use Conda or Pip to Reinstall Matplotlib and Dependencies
If upgrading doesn’t help, a clean reinstall often fixes hidden issues.
Using pip:
pip uninstall matplotlib
pip install matplotlibOr if you use Anaconda:
conda remove matplotlib
conda install matplotlibAfter reinstalling, try your 3D plot code again.
4: Verify Your Code Syntax and Environment
Sometimes the error can be as simple as a typo or running code in an environment that doesn’t support graphical output properly (like some headless servers).
- Double-check that your
projection='3d'argument is spelled correctly. - Make sure your Python environment supports GUI backend for Matplotlib. For example, Jupyter notebooks or standard Python scripts on Windows/macOS usually work fine.
- If you’re running scripts on a remote server, you might need to use a virtual display like Xvfb or save plots to files instead of showing them.
Read Matplotlib Multiple Bar Chart
Bonus Tips for Smooth 3D Plotting in Matplotlib
- Always start your script with the necessary imports:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D- Use
fig = plt.figure()andax = fig.add_subplot(111, projection='3d')to create your 3D axes. - If you want to create scatter or surface plots, Matplotlib offers
ax.scatter(),ax.plot_surface(), and more. - For complex 3D visualization, consider supplementing Matplotlib with libraries like Plotly or Mayavi.
Getting past the “unknown projection ‘3d’” error is usually just a matter of ensuring you have the right imports and a proper Matplotlib installation. Once you fix it, you’ll be able to create stunning 3D visualizations for your data analysis, scientific research, or any Python project.
You may also like to read:

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.