2016-04-15 4 views
1

get_path()が何であるか知っていますか?matplotlib.patchesから返されますか?円のget_path()は、元の円とは異なるものを返しています。これは、下のコードの結果からわかります。添付の写真からわかるように、オリジナルのオレンジ色の円は、元の円のget_path()の青色の円と全く異なります。get_path()matplotlib.patchesから円を返します。

import numpy as np 
import matplotlib 
from matplotlib.patches import Circle, Wedge, Polygon, Ellipse 
from matplotlib.collections import PatchCollection 
import matplotlib.pyplot as plt 
import matplotlib.patches as matpatches 


fig, ax = plt.subplots(figsize=(8, 8)) 
patches = [] 


circle = Circle((2, 2), 2) 
patches.append(circle) 

print patches[0].get_path() 
print patches[0].get_verts() 

polygon = matpatches.PathPatch(patches[0].get_path()) 
patches.append(polygon) 


colors = 2*np.random.rand(len(patches)) 
p = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4) 
p.set_array(np.array(colors)) 
ax.add_collection(p) 

plt.axis([-10, 10, -10, 10]) 

plt.show() 

fig.savefig('test.png') 

contain2 = patches[0].get_path().contains_points([[0.5, 0.5], [1.0, 1.0]]) 
print contain2 
contain3 = patches[0].contains_point([0.5, 0.5]) 
print contain3 
contain4 = patches[0].contains_point([1.0, 1.0]) 
print contain4 

答えて

1

円のパスは、単位円、あなたが2次元アフィン介して変換され、指定中心及び半径の円として表示さmatplotlibの方法です。 のパスに変換する場合は、のパスとトランスフォームの両方に適用し、パスに変換を適用する必要があります。

# Create the initial circle 
circle = Circle([2,2], 2); 

# Get the path and the affine transformation 
path = circle.get_path() 
transform = circle.get_transform() 

# Now apply the transform to the path 
newpath = transform.transform_path(path) 

# Now you can use this 
polygon = matpatches.PathPatch(newpath) 
patches.append(polygon) 
+0

それが問題を解決します。ありがとうございました。 –

関連する問題