Matplotlib 3D plotting: how to import

For 3D plotting to work in Matplotlib, near the beginning of the first .py file you use to start your program, you must have imports in this order:

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

If you try importing Axes3D in a later function that actually does the 3D plotting, it may give a runtime error.

If you feel you may use either function as an entry point, you can put the above 3 lines of code in both functions.

Post a Comment

Your email address is never shared. Required fields are marked *