'Unable to Plot 3d Function Using Matplotlib

I am trying to plot a 3d function in python using matplotlib. For some reason I get the error "Invalid syntax (pyflakes E)" in the second line of the code provided when trying to plot it. I got this part from another person, and this works for them. The packages from matplotlib I have installed are mplot3d, cm, and Subplot. Perhaps there is another package I need?

fig = plt.figure(figsize=(12,12))
ax = fig.add_subplot(projection='3d')


Solution 1:[1]

https://jakevdp.github.io/PythonDataScienceHandbook/04.12-three-dimensional-plotting.html#:~:text=In%C2%A0%5B3%5D%3A-,fig%20%3D%20plt.figure()%0Aax%20%3D%20plt.axes(projection%3D%273d%27),-With%20this%20three

It seems that you need to use ax = plt.axes(projection = 3d)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Austin Heard