<p>Matplotlib不是一个真正的3D引擎。这是一个众所周知的问题,偶尔会出现一个与您类似的问题(请参见<a href="https://stackoverflow.com/questions/37488379/matplotlib-3dplot-extra-lines-when-dimensions-not-equal/37489040#37489040">this</a>和<a href="https://stackoverflow.com/questions/37380912/matplotlib-3d-plot-plot-surface-black/37501084#37501084">this</a>)。问题是同一件艺术品可能引发看起来不同的问题。我相信你就是这样。</p>
<p>在继续我的建议之前,让我先<a href="http://matplotlib.org/mpl_toolkits/mplot3d/faq.html" rel="nofollow noreferrer">quote this information from the maplotlib website</a>:</p>
<blockquote>
<p><strong>My 3D plot doesn’t look right at certain viewing angles</strong> </p>
<p>This is probably the most commonly reported issue with mplot3d. The problem is
that – from some viewing angles – a 3D object would appear in front of
another object, even though it is physically behind it. This can
result in plots that do not look “physically correct.”</p>
<p>Unfortunately, while some work is being done to reduce the occurance
of this artifact, it is currently an intractable problem, and <strong>can not</strong>
<strong>be fully solved until matplotlib supports 3D graphics rendering at its</strong>
<strong>core</strong>.</p>
<p>The problem occurs due to the reduction of 3D data down to 2D +
z-order scalar. A single value represents the 3rd dimension for all
parts of 3D objects in a collection. Therefore, when the bounding
boxes of two collections intersect, it becomes possible for this
artifact to occur. Furthermore, the intersection of two 3D objects
(such as polygons or patches) can not be rendered properly in
matplotlib’s 2D rendering engine.</p>
<p><strong>This problem will likely not be solved until OpenGL support is added</strong>
to all of the backends (patches are greatly welcomed). Until then, if
you need complex 3D scenes, we recommend using <a href="http://docs.enthought.com/mayavi/mayavi/" rel="nofollow noreferrer">MayaVi</a>.</p>
</blockquote>
<p><a href="http://docs.enthought.com/mayavi/mayavi/auto/changes.html?highlight=python3" rel="nofollow noreferrer">It seems that Mayavi has finally moved on to Python 3</a>,这当然是一种可能性。如果要坚持使用matplotlib进行此类绘图,我的建议是使用rstride和cstride值来查看哪些值可以生成令您满意的绘图。</p>
<pre><code>surf = ax.plot_surface( X, Y, Z,
rstride=5, cstride=5,
cmap='jet',
alpha=1,
linewidth=0,
antialiased=True,
vmin=0,
rstride=10,
cstride=10,
vmax=z_scale
)
</code></pre>
<p>另一种可能是尝试看看其他类型的3D绘图是否更好。检查<a href="http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots" rel="nofollow noreferrer">plot_trisurf</a>、<a href="http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#contour-plots" rel="nofollow noreferrer">contour</a>或<a href="http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#filled-contour-plots" rel="nofollow noreferrer">contourf</a>。我知道这不太理想,但在过去我也设法做到了。</p>
<p>很抱歉没有更满意的答复。或许其他的用户对此有更好的解决方案。祝你好运。</p>