Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将edgecolor设置为与trisurf中的facecolor匹配_Python_Matplotlib_Mplot3d - Fatal编程技术网

Python 将edgecolor设置为与trisurf中的facecolor匹配

Python 将edgecolor设置为与trisurf中的facecolor匹配,python,matplotlib,mplot3d,Python,Matplotlib,Mplot3d,我正在尝试使用python3和matplotlib(版本1.4.0)绘制球体表面上定义的标量函数。我希望在球体上相对均匀地分布面,因此我不使用网格网格。这导致我使用plot\u trisurf来绘制我的函数。我已经用一个普通的标量函数对它进行了测试,我遇到了一个问题,即沿面边缘渲染人工制品: 我用于创建绘图的代码如下所示: from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as

我正在尝试使用python3和matplotlib(版本1.4.0)绘制球体表面上定义的标量函数。我希望在球体上相对均匀地分布面,因此我不使用网格网格。这导致我使用
plot\u trisurf
来绘制我的函数。我已经用一个普通的标量函数对它进行了测试,我遇到了一个问题,即沿面边缘渲染人工制品: 我用于创建绘图的代码如下所示:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.tri as mtri
from scipy.spatial import ConvexHull

def points_on_sphere(N):
    """ Generate N evenly distributed points on the unit sphere centered at
    the origin. Uses the 'Golden Spiral'.
    Code by Chris Colbert from the numpy-discussion list.
    """
    phi = (1 + np.sqrt(5)) / 2 # the golden ratio
    long_incr = 2*np.pi / phi # how much to increment the longitude

    dz = 2.0 / float(N) # a unit sphere has diameter 2
    bands = np.arange(N) # each band will have one point placed on it
    z = bands * dz - 1 + (dz/2) # the height z of each band/point
    r = np.sqrt(1 - z*z) # project onto xy-plane
    az = bands * long_incr # azimuthal angle of point modulo 2 pi
    x = r * np.cos(az)
    y = r * np.sin(az)
    return x, y, z

def average_g(triples):
    return np.mean([triple[2] for triple in triples])

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y, Z = points_on_sphere(2**12)

Triples = np.array(list(zip(X, Y, Z)))

hull = ConvexHull(Triples)
triangles = hull.simplices

colors = np.array([average_g([Triples[idx] for idx in triangle]) for
                   triangle in triangles])

collec = ax.plot_trisurf(mtri.Triangulation(X, Y, triangles),
        Z, shade=False, cmap=plt.get_cmap('Blues'), array=colors,
        edgecolors='none')
collec.autoscale()

plt.show()
这个问题似乎已经在中讨论过,但我似乎不知道如何设置EdgeColor以匹配面部颜色。我尝试过的两件事是设置
edgecolors='face'
和调用
collec.set\u edgecolors()
,使用各种参数,但这些参数会抛出
AttributeError:'Poly3DCollection'对象没有属性'\u facecolors2d'


如何将edgecolor设置为trisurf绘图中的facecolor?

您可以将
plot\u trisurf()
抗锯齿参数设置为
False
。结果如下:


这确实解决了边缘上的人工制品问题。如果有一种方法可以在不禁用抗锯齿的情况下解决这个问题,那就太好了,我认为适当地设置边缘颜色应该可以做到这一点。如果没有人能想出一种方法来设置边缘颜色以匹配
plot\u trisurf
中的面部颜色,那么我很乐意接受这个答案。