2

我一直试图在表面上叠加一条线,但我有一个小问题。有一些视点看不到这条线。例如,尝试绘制由以下代码生成的表面:

from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import axes3d, Axes3D
import pylab as p
import matplotlib.ticker as ticker 
from matplotlib.colors import LightSource

vima=0.2

def fun(x, y):
  return x**3 + y

fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(0.1, 50, vima)
Y = np.arange(0.1, 10.2, vima)
X, Y = np.meshgrid(X, Y)

Z=fun(X,Y)

surf = ax.plot_surface(X, Y, Z,rstride=25, cstride=75, alpha=1, color='0.8',  linewidth=0.2, shade=True)

Y=(10.0-0.2*X)/0.9798
Z=Z*0
ax.plot_surface(X,Y,Z)
ax.grid(on=True)
ax.view_init(elev=34,azim=-106)

Z=fun(X,Y)
ax.plot_surface(X,Y,Z)#, linewidth=1)

ax.w_xaxis.set_major_locator(ticker.NullLocator()) 
ax.w_yaxis.set_major_locator(ticker.NullLocator()) 
ax.w_zaxis.set_major_locator(ticker.NullLocator()) 


ax.set_xlabel('$x$')

ax.set_ylabel('$y$')
ax.set_zlabel('$z$')


fig.suptitle('b', fontsize=14)

plt.show()

我假设最初你可以看到表面,xy 平面上的一条线和一条叠加在表面上的线。但是如果你旋转这个图,你会发现有些视点叠加的线是不可见的。

有没有办法克服这个小错误?

先感谢您

4

0 回答 0