Black Lives Matter. Please consider donating to Black Girls Code today.

Sub-level/contour plot

I am interested in making sub-level or sub-contour plots of surfaces in plotly. That is, I would like to plot all z-values on a surface which are less than or equal to some threshold value. In my particular case, I plot the surface using a numpy meshgrid. Parts of the surface have a parameterization such that naive thresholding produces very ugly results, as in

I understand this is due to my (cubic) parameterization of the surface and the way I have implemented the threshold (only plotting z(x,y) if z(x,y) <= some threshold).

Is there a ‘smarter’ way to do this?

It seems like, internally, plotly computes what I would need–the actual contour line. I can see this by hovering on the surface. In the above picture, these are the black lines given by intersecting the surface with z = constant. Really, I want the contour line and everything below it, but I think if I could get the contour line, I could plot everything below it.

Thanks for any help you can provide.

Sorry-setting the z-axis range in scene in layout does the trick!