在下面的代码中,我画了一条线,然后在它上面画了一个不透明的补丁(alpha=1)。我希望被补丁覆盖的那部分线被隐藏起来,但它看起来就像是在补丁之后画的线。如何改变它,使线不显示出来?
代码改编自这个matplotlib示例
import matplotlib.path as mpath
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
Path = mpath.Path
path_data = [
(Path.MOVETO, (1.58, -2.57)),
(Path.CURVE4, (0.35, -1.1)),
(Path.CURVE4, (-1.75, 2.0)),
(Path.CURVE4, (0.375, 2.0)),
(Path.LINETO, (0.85, 1.15)),
(Path.CURVE4, (2.2, 3.2)),
(Path.CURVE4, (3, 0.05)),
(Path.CURVE4, (2.0, -0.5)),
(Path.CLOSEPOLY, (1.58, -2.57)),
]
codes, verts = zip(*path_data)
path = mpath.Path(verts, codes)
# plot control points and connecting lines
x, y = zip(*path.vertices)
y2 = [_y-1 for _y in y]
line, = ax.plot(x, y2, 'go-')
patch = mpatches.PathPatch(path, facecolor='r', alpha=1)
ax.add_patch(patch)
ax.grid()
ax.axis('equal')
plt.show()
1条答案
按热度按时间xyhw6mcr1#
您可以指定补丁的z顺序(绿色行的
zorder
2,因此任何> 2都可以):