Python 有没有一种方法可以绘制一侧带有圆弧的matplotlib面片矩形?
我需要画一个多边形,它有4条边,右边是圆弧。与此类似: 我曾尝试将matplotlib提供的代码用于bezier曲线,但没有成功。任何帮助都将不胜感激:)Python 有没有一种方法可以绘制一侧带有圆弧的matplotlib面片矩形?,python,matplotlib,Python,Matplotlib,我需要画一个多边形,它有4条边,右边是圆弧。与此类似: 我曾尝试将matplotlib提供的代码用于bezier曲线,但没有成功。任何帮助都将不胜感激:) 我不知道这是否是绘制路径对象的正确方法-您最好等待有此方法经验的人。但在此之前,您可以这样做: from matplotlib.path import Path import matplotlib.patches as patches verts = [ (0, 0), # P0 (0, 1), # P1
我不知道这是否是绘制路径对象的正确方法-您最好等待有此方法经验的人。但在此之前,您可以这样做:
from matplotlib.path import Path
import matplotlib.patches as patches
verts = [
(0, 0), # P0
(0, 1), # P1
(1, 1), # P2
(0.4, 1), #these are the vertices for the
(0.2, 0), #Bezier curve
(0.5, 0), # P3
(0, 0) #and back to P0
]
codes = [
Path.MOVETO, # P0
Path.LINETO, #line to P1
Path.LINETO, #line to P2
Path.CURVE4, #control point one for the Bezier curve
Path.CURVE4, #control point two
Path.CURVE4, #end point for the Bezier curve
Path.LINETO #and back to P0
]
path = Path(verts, codes)
fig, ax = plt.subplots()
patch = patches.PathPatch(path, facecolor='none', lw=2)
ax.add_patch(patch)
#you can add the hull figure for the Bezier curve
#xs, ys = zip(*verts)
#ax.plot(xs, ys, "x--", lw=2, color='black', ms=10)
ax.set_xlim(-0.1, 1.1)
ax.set_ylim(-0.1, 1.1)
plt.show()
样本输出:
表示对于贝塞尔曲线,除了当前位置之外,还需要两个控制点和一个端点。因此,您的四点方法可能还不够。非常感谢!这正是我需要的
from matplotlib.path import Path
import matplotlib.patches as patches
verts = [
(0, 0), # P0
(0, 1), # P1
(1, 1), # P2
(0.4, 1), #these are the vertices for the
(0.2, 0), #Bezier curve
(0.5, 0), # P3
(0, 0) #and back to P0
]
codes = [
Path.MOVETO, # P0
Path.LINETO, #line to P1
Path.LINETO, #line to P2
Path.CURVE4, #control point one for the Bezier curve
Path.CURVE4, #control point two
Path.CURVE4, #end point for the Bezier curve
Path.LINETO #and back to P0
]
path = Path(verts, codes)
fig, ax = plt.subplots()
patch = patches.PathPatch(path, facecolor='none', lw=2)
ax.add_patch(patch)
#you can add the hull figure for the Bezier curve
#xs, ys = zip(*verts)
#ax.plot(xs, ys, "x--", lw=2, color='black', ms=10)
ax.set_xlim(-0.1, 1.1)
ax.set_ylim(-0.1, 1.1)
plt.show()