Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: Unknown projection '3d' (once again)

When executing this line of code:

import matplotlib.pyplot as plt

#your code

fig = plt.figure()
ax = fig.gca(projection='3d')

I have an output error:

raise ValueError("Unknown projection %r" % projection)

ValueError: Unknown projection '3d'

<Figure size 432x288 with 0 Axes>

The error appears also when I use Spyder as IDE. The version of matplotlib is

print('matplotlib: {}'.format(matplotlib.__version__))
matplotlib: 1.5.0rc3

But I had the same problem even with other versions of matplotlib. A similar error was reported in this question (Stackoverflow) but the answers do not help. Some suggestions on how to modify the instruction? matplotlib: 3.0.2

like image 778
Leos313 Avatar asked May 20 '19 13:05

Leos313


1 Answers

You will have to import Axes3D to enable the 3d plotting in matplotlib. The official tutorials on 3d plotting can be found here. So the correct imports and code would look like

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D # <--- This is important for 3d plotting 

#your code

fig = plt.figure()
ax = fig.gca(projection='3d')
like image 172
Sheldore Avatar answered Nov 17 '22 09:11

Sheldore