Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python get_path()从matplotlib.patches返回圆_Python_Matplotlib - Fatal编程技术网

Python get_path()从matplotlib.patches返回圆

Python get_path()从matplotlib.patches返回圆,python,matplotlib,Python,Matplotlib,有人知道从matplotlib.patches返回的get_path()圆的返回什么吗?圆的get_path()返回与原始圆不同的内容,这可以从下面代码的结果中看出。从附图中可以看出,原始橙色圆圈与原始圆圈的get_path()中的蓝色圆圈完全不同 import numpy as np import matplotlib from matplotlib.patches import Circle, Wedge, Polygon, Ellipse from matplotlib.collectio

有人知道从
matplotlib.patches
返回的
get_path()
圆的
返回什么吗?圆的
get_path()
返回与原始圆不同的内容,这可以从下面代码的结果中看出。从附图中可以看出,原始橙色圆圈与原始圆圈的
get_path()
中的蓝色圆圈完全不同

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

圆的路径是单位圆,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)