Matplotlib 3d: surface does not cover a line

594 views Asked by At

I draw a plane and a line crossing the plane.

import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3

def plot_x_axis(ax):
    x = np.array([-1, 1])
    y = np.array([0, 0])
    z = np.array([0, 0])
    ax.plot(x, y, z, color='green')

def plot_yz_plane(ax):
    a = np.array([0, 1, 0])
    b = np.array([0, 0, 1])
    U, V = np.meshgrid(np.linspace(-0.5, 0.5, 3), np.linspace(-0.5, 0.5, 3))
    x = a[0] * U + b[0] * V
    y = a[1] * U + b[1] * V
    z = a[2] * U + b[2] * V
    surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, alpha=1.0, color='red')

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plot_x_axis(ax)
plot_yz_plane(ax)
plt.show()

I expect that a part of this line (placed behind the plane) will be covered by the plane, but actually matplotlib shows all the objects as if the plane is transparent. How to fix this problem?

0

There are 0 answers