6
我正在matplotlib中绘制一个多边形。我把所有的点的坐标。在某些点之间,我希望有“圆”或“径向”边而不是直线(比如图上的点1和2),这是可能的吗?如果不是最有效的方法是什么?matplotlib - 多边形边的半径 - 有可能吗?
编辑: 拉特格解决方案工作良好
我正在matplotlib中绘制一个多边形。我把所有的点的坐标。在某些点之间,我希望有“圆”或“径向”边而不是直线(比如图上的点1和2),这是可能的吗?如果不是最有效的方法是什么?matplotlib - 多边形边的半径 - 有可能吗?
编辑: 拉特格解决方案工作良好
您可以通过路径使多边形用弧线
正常方:。
import matplotlib.path as mpath
import matplotlib.patches as patches
verts = [(0,0),
(1,0),
(1,1),
(0,1),
(0,0)]
codes = [mpath.Path.MOVETO] + (len(x)-1)*[mpath.Path.LINETO]
square_verts = mpath.Path(verts, codes)
fig, ax = plt.subplots(subplot_kw={'aspect': 1.0, 'xlim': [-0.2,1.2], 'ylim': [-0.2,1.2]})
square = patches.PathPatch(square_verts, facecolor='orange', lw=2)
ax.add_patch(square)
圆方可以进行:
verts = [(0.2, 0.0),
(0.8, 0.0), # start of the lower right corner
(1.0, 0.0), # intermediate point (as if it wasn't rounded)
(1.0, 0.2), # end point of the lower right corner
(1.0, 0.8), # move to the next point etc.
(1.0, 1.0),
(0.8, 1.0),
(0.2, 1.0),
(0.0, 1.0),
(0.0, 0.8),
(0.0, 0.2),
(0.0, 0.0),
(0.2, 0.0)]
codes = [mpath.Path.MOVETO,
mpath.Path.LINETO,
mpath.Path.CURVE3,
mpath.Path.CURVE3,
mpath.Path.LINETO,
mpath.Path.CURVE3,
mpath.Path.CURVE3,
mpath.Path.LINETO,
mpath.Path.CURVE3,
mpath.Path.CURVE3,
mpath.Path.LINETO,
mpath.Path.CURVE3,
mpath.Path.CURVE3]
rounded_verts = mpath.Path(verts, codes)
fig, ax = plt.subplots(subplot_kw={'aspect': 1.0, 'xlim': [-0.2,1.2], 'ylim': [-0.2,1.2]})
rounded_verts = patches.PathPatch(rounded_verts, facecolor='orange', lw=2)
ax.add_patch(rounded_verts)
对于你的榜样,你就需要指定它从点1使用x-coordinate
中间点和来自Point2的y-coordinate
。
的matplotlib路径教程提供的路径如何进行的详细介绍: http://matplotlib.org/users/path_tutorial.html
你的意思是要适合平滑曲线? – doctorlove
我是指有两个指定点和半径的拱门。 –