def plot_chord(begin, end, spacing, color, alpha=None):
"""Plots a circular chord from begin to end.
This assumes that the outer circle is centered at (0,0).
Args:
begin: A [2]-shaped numpy array.
end: A [2]-shaped numpy array.
spacing: A float, extra spacing around the edge of the circle.
color: A matplotlib color spec.
apha: A float or None.
"""
# Adapted from https://matplotlib.org/users/path_tutorial.html
codes = [Path.MOVETO, Path.CURVE4, Path.CURVE4, Path.CURVE4]
xy = np.array([begin, begin, end, end])
dist = ((begin - end)**2).sum()**0.5
xy[[1, 2], :] *= 1 - 2 / 3 * dist + 1 / 6 * dist**2 - spacing
path = Path(xy, codes)
patch = PathPatch(
path, facecolor='none', edgecolor=color, lw=1, alpha=alpha)
pyplot.gca().add_patch(patch)
评论列表
文章目录