这个MWE证明了这个问题:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
n = 100
x = np.linspace(0, 1, n)
y = np.linspace(0, 1, n)
X, Y = np.meshgrid(x, y)
Z = np.zeros((n, n))
for i in xrange(n):
for j in xrange(n):
Z[j, i] = x[i] + 10.0*y[j]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z)
ax.set_xlabel('x')
ax.set_ylabel('y')
# add line x + y = 1
ax.plot(X[X + Y == 1], Y[X + Y == 1], Z[X + Y == 1], '--r')
# add contours, comment this to make line above appear
cset = ax.contourf(X, Y, Z, zdir='z', offset=np.min(Z))
plt.show()
注释掉行cset = ax.contourf(X, Y, Z, zdir='z', offset=np.min(Z))
后,图片为
但我想添加轮廓,当我们重新添加该线时,虚线会消失:
是什么给出的?另外,是否有更好的方法来添加轮廓?