Issue
I'm using matplotlib
to plot 3D triangulated surface. However even if didn't define any alpha value the plot is semi transparent. I would like to make it completely opaque.
dataset
is the array storing the mesh information.
norm = matplotlib.colors.Normalize()
fvalue=np.zeros(np.size(dataset.tri,0))
for i in range(0,np.size(dataset.tri,0)):
tri=dataset.tri[i]
fvalue[i]=dataset.var['T'][0,int(tri[0])]
colors = custom_colormap(norm(fvalue))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
p3dc = ax.plot_trisurf(dataset.coord[0], dataset.coord[1],dataset.coord[2], triangles=dataset.tri)
p3dc.set_fc(colors)
plt.show()
Solution
The problem seems to result from incorrectly using the axes method set_fc
(set_facecolor) instead of set_color
. The set_color
method assigns both edge and face colors. The example below illustrates the difference:
where the code is:
import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d
# create dataset ................................................
class data :
def __init__(self) :
def varT(rtp) :
x,y,z = s3d.SphericalSurface.coor_convert(rtp,True)
return -np.cos(2*(z+1)*np.pi)
surface = s3d.SphericalSurface(5)
surface.map_cmap_from_op(varT,cmap='seismic')
self.coord = surface.vertexCoor.T
self.tri = surface.fvIndices
self.colors = surface.facecolors
dataset = data()
# show figure, comparing set_facecolor to set_color .............
fig = plt.figure(figsize=(6,3))
ax = fig.add_subplot(121, projection='3d')
ax.set_title("set_facecolor")
p3dc = ax.plot_trisurf(dataset.coord[0], dataset.coord[1],dataset.coord[2], triangles=dataset.tri)
p3dc.set_facecolor(dataset.colors)
ax2 = fig.add_subplot(122, projection='3d')
ax2.set_title("set_color")
p3dc = ax2.plot_trisurf(dataset.coord[0], dataset.coord[1],dataset.coord[2], triangles=dataset.tri)
p3dc.set_color(dataset.colors)
fig.tight_layout()
plt.show()
There seems a lot of discussions regarding this problem. The problem is not Matplotlib rendering, but an insufficient explanation in the Matplotlib documentation regarding color, facecolor, edgecolor and linewidth. These properties interact to create the resulting visualization. This problen even gets worse when transparent surfaces are used. A further discussion of this rendering 'artifact' is in the S3Dlib documentation.
Answered By - Dr.Z
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.