With matplotlib.patches, the patch.contains_point(xy) method seems to work differently from patch.get_path().contains_point(xy), at least after having added the patch to the axes. See difference True/True and True/False below. I can't find any documentation on this difference. Does anybody know? I also have difficulty seeing how contains_point() decides if the point is inside the path given the path's vertices are the unit rectangle in this case and not the rectangle I specified.
fig, ax = plt.subplots()
rect = patches.Rectangle([0.2, 0.3], 0.8, 0.5)
pnt = [0.4, 0.45] # point inside rect
print("Before adding patch to axes:")
print(rect.get_path().vertices)
print(rect.contains_point(pnt))
print(rect.get_path().contains_point(pnt))
print("After adding patch to axes")
ax.add_patch(rect)
print(rect.get_path().vertices)
print(rect.contains_point(pnt))
print(rect.get_path().contains_point(pnt))
plt.show()
Before adding patch to axes:
[[0. 0.]
[1. 0.]
[1. 1.]
[0. 1.]
[0. 0.]]
True
True
After adding patch to axes
[[0. 0.]
[1. 0.]
[1. 1.]
[0. 1.]
[0. 0.]]
False
True