1
有沒有人知道從matplotlib.patches
返回的Circle
的get_path()
是什麼?圓圈的get_path()
正在返回與原始圓圈不同的東西,這可以從下面的代碼結果中看出。從附圖中可以看出,原始橙色圈與原始圈的get_path()
的藍色圈完全不同。get_path()從matplotlib.patches返回一個Circle
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
解決了問題!謝謝。 –