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 と同じに設定するにはどうすればよいですか?