I want a numpy array plotted as a 3D surface and the zero contour line to be highlighted in a striking color. I use the following code to plot the surface (k_mean
is the array to be plotted):
fig = plt.figure()
ax = fig.gca(projection='3d')
X,Y=np.meshgrid(range(k_mean.shape[0]), range(k_mean.shape[1]))
Z=k_mean
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,linewidth=0., edgecolor=None, alpha=0.8, cmap=cm.nipy_spectral, antialiased=False)
cset = ax.contour(X, Y, Z, zdir='z', offset=0, cmap=cm.nipy_spectral)
cset = ax.contour(X, Y, Z, zdir='x', offset=0, cmap=cm.nipy_spectral)
cset = ax.contour(X, Y, Z, zdir='y', offset=120, cmap=cm.nipy_spectral)
ax.set_xlim(0, 120)
ax.set_ylim(0, 120)
ax.set_zlim(0, 1)
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
Now I have added the following line that works fine for itself:
cs=plt.contour(X,Y,Z,levels=[0], colors='g', linewidths=3)
But depending on where I insert it, either only the surface plot or the contour line is plotted.
How can If fix it in the way that the zero contour line appears on top of the surface?