How can I connect and plot parts of 2D slices over a certain threshold?

43 Views Asked by At

I want to connect binary surfaces in a surfaceplot, to achive a 3D connecting contour.

So far I plotted the 2D slices in this minimal example:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d   import Axes3D
from matplotlib.collections import PolyCollection
import matplotlib
matplotlib.use('Qt5Agg')

x, y = np.meshgrid(np.linspace(0,1,20), np.linspace(0,1,20))
z = np.linspace(0, 2, 4)

u = np.zeros((len(z),20,20))

for i in range(len(z)):
    u[i, i+5:i+7, i+5:i+7] = 1

ax = plt.figure().add_subplot(111, projection = '3d')
for i in range(len(z)):
    im = ax.pcolor(x, y, u[i,:,:], alpha=0.1) 
    ax.add_collection3d(im, zs=z[i], zdir='z')    
plt.show()

enter image description here

Does anybody have an idea on how to connect these yellow areas to a 3D contour and plot it? Thanks a lot! Here is an example of what I want to get: enter image description here

0

There are 0 best solutions below