回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我试图从一组指定z值的数据中绘制一个3D曲面。我得到了一些奇怪的透明艺术品,在那里我可以透过表面看到,即使我设置alpha=1.0。</p>
<p>打印时和保存到文件时(均为png和pdf格式)都会显示该工艺品:
<a href="https://i.stack.imgur.com/2bXbI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2bXbI.png" alt="enter image description here"/></a></p>
<p>我试过改变线条宽度,把步幅从1改为10(在后一种情况下,由于分辨率太粗糙,表面不可见)。</p>
<p>问:我怎样才能摆脱这种透明性?</strong></p>
<p>这是我的代码:</p>
<pre><code>import sys
import numpy as np
import numpy.ma as ma
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
y_label = r'x'
x_label = r'y'
z_label = r'z'
x_scale = 2.0*np.pi
y_scale = 2.0*np.pi
y_numPoints = 250
x_numPoints = 250
def quasiCrystal(x, y):
z = 0
for i in range(0,5):
z += np.sin(x * np.cos(float(i)*np.pi/5.0) +
y * np.sin(float(i)*np.pi/5.0))
return z
x = np.linspace(-x_scale, x_scale, x_numPoints)
y = np.linspace(-y_scale, y_scale, y_numPoints)
X,Y = np.meshgrid(x,y)
Z = quasiCrystal(X, Y)
f = plt.figure()
ax = f.gca(projection='3d')
surf = ax.plot_surface( X, Y, Z,
rstride=5, cstride=5,
cmap='seismic',
alpha=1,
linewidth=0,
antialiased=True,
vmin=np.min(Z),
vmax=np.max(Z)
)
ax.set_zlim3d(np.min(Z), np.max(Z))
f.colorbar(surf, label=z_label)
ax.set_xlabel(x_label)
ax.set_ylabel(y_label)
ax.set_zlabel(z_label)
plt.show()
</code></pre>
<p>下面是我的实际数据的另一张图片,在这里更容易看到实物:
<a href="https://i.stack.imgur.com/nXivZ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nXivZ.png" alt="enter image description here"/></a></p>