在matplotlib中正确渲染3d plot_surface

时间:2015-12-11 16:03:30

标签: python matplotlib 3d surface

我正在尝试渲染表面,但我无法获得漂亮的可视化效果。来自plot_surface的{​​{1}}函数给出了下图:

plot_surface

由下面的代码生成。如果仔细观察,我如何摆脱这种透明度以及仍然可见的线框?

matplotlib

1 个答案:

答案 0 :(得分:1)

这只是一种解决方法,但这适用于大多数matplotlib例程,例如contourf(之前我遇到过同样的问题);调用绘图例程(在本例中为plot_surface)两次解决了这两个问题:

enter image description here

左图是调用plot_surface一次,右调用两次。

对于不透明的表面,设置antialiased=False有帮助(左下图),透明度antialiased=True会在多边形边缘处产生非常细的线条(我怀疑因为多边形略微重叠),但是几乎看不见(右图)。

enter image description here

fig = pl.figure()
ax = pl.subplot(121, projection='3d')
surf = ax.plot_surface(xx/1000., yy/1000., h, alpha=1.0, cstride=1, rstride=1, linewidth=0, antialiased=False)

ax = pl.subplot(122, projection='3d')
surf = ax.plot_surface(xx/1000., yy/1000., h, alpha=0.3, cstride=1, rstride=1, linewidth=0, antialiased=True)