Mplot3d из Matplotlib имеет проблемы с перекрытием; как построить 2D полигоны в Mayavi? - PullRequest
0 голосов
/ 21 июня 2020

Я создаю очень простые 3D-графики, которые состоят из нескольких 2D-полигонов, уложенных друг на друга. correct

Depending on the viewing angle the overlapping problem occurs. enter image description here

The matplotlib FAQ recommends to use mayavi, but I have no idea how to achieve this result. This is what my code looks like with matplotlib (reduced to a single polygon).

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import numpy as np

fig = plt.figure()
ax = Axes3D(fig)

xmin = None
xmax = None
ymin = None
ymax = None

kp = -1

vertices = [np.array([[-4., -12.5], [-0.80351528, -0.], [-2.69648472, 0.]])]

for vert in vertices:
    x = vert[:, 0]
    y = vert[:, 1]
    z = kp * np.ones_like(x)
    nodes = list(zip(x, y, z))

    if xmin is None:
        xmin = min(x)
    else:
        xmin = min(xmin, min(x))
    if xmax is None:
        xmax = max(x)
    else:
        xmax = max(xmax, max(x))

    if ymin is None:
        ymin = min(y)
    else:
        ymin = min(ymin, min(y))
    if ymax is None:
        ymax = max(y)
    else:
        ymax = max(ymax, max(y))

    poly = Poly3DCollection([nodes], facecolors=['r'], edgecolors=['k'])
    ax.add_collection3d(poly)

ax.set_ylim3d(ymin, ymax)
ax.set_ylabel('ki')
ax.set_xlim3d(xmin, xmax)
ax.set_xlabel('kd')
ax.set_zlim3d(kp, kp)
ax.set_zlabel('kp')

plt.show()

Благодарю за каждую подсказку.

...