Help needed to avoid Deprecation warning

Hi first timer.
I have fully working code that generates a warning. I don’t know enough yet to fix it. Please help.

Code is

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(X, Y, Z, facecolors=colors, linewidth=0)
ax.set_zlim(1, 11)
ax.zaxis.set_major_locator(LinearLocator(6))

plt.show()

The second line throws “MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot()”

Any advice appreciated.

Regards

Drisky

Fig.subplot should work in your case.

yes, use subplots.

fig,ax = plt.subplots(... subplot_kw={"projection":"3d"} )
ax.plot_surface(X,Y,Z)

Hi @Drisky Use subplots.