Masked 3D surface plots with holes and smooth edges in Python - workaround

Опубликовано: 17 Июль 2026
на канале: ComputationalScientist
3,184
45

Matplotlib's 'plot_surface' function can't handle masked arrays properly (either masking with NaNs or using numpy masked arrays).

To plot a masked surface with 'plot_surface', a small trick must be applied. Sadly, the edges are not smooth even with this method.

Another function 'plot_trisurf' can be the solution to this problem. In this tutorial, I cover this approach after demonstrating what's wrong with 'plot_surface'.


Music by 4barrelcarb at https://freesound.org/people/4barrelc...
Sound effects obtained from https://www.zapsplat