[英]How to increase the number of vertices?
I need a parametric form for a matplotlib.path.Path
.我需要
matplotlib.path.Path
的参数形式。 So I used the .vertices
attribute, and it works fine except that the number of points given is too low for the use I want.所以我使用了
.vertices
属性,它工作正常,除了给定的点数对于我想要的用途来说太低了。 Here is a code to illustrate:下面用一段代码来说明:
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.patches as mpat
fig, ax = plt.subplots()
ax.set(xlim=(-6, 6), ylim=(-6, 6))
# generate a circular path
circle = mpat.Arc((0, 0), 10, 10, theta1=20, theta2=220, color='green')
path = circle.get_transform().transform_path(circle.get_path()).cleaned().vertices[:-3] # get_path is not enough because of the transformation, so we apply to the path the same transformation as the circle has got from the identity circle
ax.add_patch(circle)
# plot path vertices
plt.scatter(x=path[:, 0], y=path[:, 1], color='red', s=2)
shape = len(path)
plt.show()
How to increase the number of points (red) to fetch better the path (green)?如何增加点数(红色)以获取更好的路径(绿色)? Or, how can I increase the
len
of path
?或者,我怎样才能增加
len
的path
?
Thanks in advance!提前致谢!
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.patches as mpat
fig, ax = plt.subplots()
ax.set(xlim=(-6, 6), ylim=(-6, 6))
# generate a circular path
circle = mpat.Arc((0, 0), 10, 10, theta1=20, theta2=220, color='green')
path = circle.get_transform().transform_path(circle.get_path()).cleaned().vertices[:-3] # get_path is not enough because of the transformation, so we apply to the path the same transformation as the circle has got from the identity circle
ax.add_patch(circle)
# plot path vertices
plt.scatter(x=path[:, 0], y=path[:, 1], color='red', s=2)
shape = len(path)
plt.show()
It's not ideal, but you can just loop over many shorter arcs, eg,:这并不理想,但您可以遍历许多较短的弧线,例如:
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.patches as mpat
fig, ax = plt.subplots()
ax.set(xlim=(-6, 6), ylim=(-6, 6))
# generate a circular path
dr = 30 # change this to control the number of points
path = np.empty((0, 2))
for i in range(20, 221, dr):
circle = mpat.Arc((0, 0), 10, 10, theta1=i, theta2=(i + dr), color='green')
tmppath = circle.get_transform().transform_path(circle.get_path()).cleaned().vertices[:-1]
path = np.vstack((path, tmppath[:, 0:2]))
ax.add_patch(circle)
# plot path vertices
plt.scatter(x=path[:, 0], y=path[:, 1], color='red', s=2)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.