I am trying to render a surface, but I do not manage to get a pretty visualisation. The plot_surface
function from matplotlib
gives me the following figure:
produced by the code below. How do I get rid of this transparency and the wireframe that is still visible if you look carefully?
import numpy as np
import matplotlib.pyplot as pl
from mpl_toolkits.mplot3d import Axes3D
pl.ion()
nx = 512
ny = 512
Lx = 2.e6
Ly = 2.e6
x = np.linspace(0., Lx, nx)
y = np.linspace(0., Ly, ny)
xx, yy = np.meshgrid(x,y)
Ld = 6.e4
h = np.exp(-( (xx - 0.5*Lx)**2 + (yy - 0.5*Ly)**2) / Ld**2 )
pl.figure()
ax = pl.subplot(111, projection='3d')
ax.plot_surface(xx/1000., yy/1000., h, alpha=1., cstride=1, rstride=1, linewidth=0)
ax.set_zlim3d(-0.2, 1.)
It's only a workaround, but this works for most matplotlib routines like eg contourf
(where I had the same problem before); calling the plot routine (in this case plot_surface
) twice solves both problems:
The left figure is with calling plot_surface
once, the right one calling it twice.
For a non-transparent surface, setting antialiased=False
helps (left figure below), with transparency antialiased=True
produces very thin lines at the polygon edges (I suspect because the polygons slightly overlap), but they are hardly visible (right figure below).
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.