Solution to error reported by ax = fig.gca(projection='3d')

I am learning tensorflow recently, and there is an exercise in using matplotlib to draw a 3D image. I encountered the following problems when running the code

TypeError: FigureBase.gca() got an unexpected keyword argument 'projection

I found that the Axes3D function was not used (line 5 in the picture). After querying and experimenting with some solutions on the Internet, I will record it now.

Solution:

ax = fig.gca(projection='3d')                                #原来的代码
ax = fig.add_axes(Axes3D(fig))                            #改正后的代码

The actual effect is shown in the figure:

Guess you like

Origin blog.csdn.net/m0_72522488/article/details/128906766