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)

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.



Fig.subplot should work in your case.

yes, use subplots.

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

Hi @Drisky Use subplots.