Matplotlib 3d: surface does not cover line

I draw a plane and a line intersecting 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 part of this line (located behind the plane) will be covered by the plane, but in fact matplotlib shows all objects as if the plane were transparent. How to solve this problem?

+3


source to share





All Articles