这并不理想,但您可以循环许多较短的弧,例如:
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()
Update
另一种选择是破解Arc https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Arc.html类,以便在初始化 https://github.com/matplotlib/matplotlib/blob/v3.6.2/lib/matplotlib/patches.py#L1898-L2143, the Path.arc https://github.com/matplotlib/matplotlib/blob/dc0328fb9c1c8817b07a5121a106a06be3571433/lib/matplotlib/path.py#L926采取在n
关键词。例如。,
from matplotlib.patches import Path, Arc
class NewArc(Arc):
def __init__(self, xy, width, height, angle=0.0, theta1=0.0, theta2=360.0, n=30, **kwargs):
"""
An Arc class with the n keyword argument
"""
fill = kwargs.setdefault('fill', False)
if fill:
raise ValueError("Arc objects can not be filled")
super().__init__(xy, width, height, angle=angle, **kwargs)
self.theta1 = theta1
self.theta2 = theta2
(self._theta1, self._theta2, self._stretched_width,
self._stretched_height) = self._theta_stretch()
# add in the n keyword here
self._path = Path.arc(self._theta1, self._theta2, n=n)
然后可以使用原始代码(没有 for 循环)并增加点数,例如,
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
ax.set(xlim=(-6, 6), ylim=(-6, 6))
# generate a circular path using NewArc and the n keyword
circle = NewArc((0, 0), 10, 10, theta1=20, theta2=220, n=40, color='green')
path = circle.get_transform().transform_path(circle.get_path()).cleaned().vertices[:-3]
ax.add_patch(circle)
# plot path vertices
ax.scatter(x=path[:, 0], y=path[:, 1], color='red', s=2)
fig.show()