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()
我希望这条线的一部分(放置在平面后面)将被平面覆盖,但实际上matplotlib显示所有对象,就像平面是透明的一样。如何解决这个问题?