0

python3 と matplotlib (バージョン 1.4.0) を使用して、球の表面に定義されたスカラー関数をプロットしようとしています。球体全体に面を比較的均等に分散させたいので、メッシュグリッドは使用していません。これによりplot_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()

この問題はこの質問で議論されているようですが、エッジカラーをフェイスカラーと一致するように設定する方法がわかりません。私が試した2つのことは、さまざまな引数を設定edgecolors='face'して呼び出すことcollec.set_edgecolors()ですが、それらはAttributeError: 'Poly3DCollection' object has no attribute '_facecolors2d'.

trisurf プロットで、edgecolor を facecolor と同じに設定するにはどうすればよいですか?

4

1 に答える 1

2

antialiasedの引数をplot_trisurf()に設定できますFalse。結果は次のとおりです。

ここに画像の説明を入力

于 2014-11-04T08:34:50.590 に答える