CDF实际上被画成一个多边形,在
matplotlib
定义为
路径
. 路径依次由顶点(到哪里)和代码(如何到达那里)定义。文件说我们不应该直接改变这些属性,但是我们可以
新的
多边形是从旧的多边形衍生出来的,适合我们的需要。
poly = ax.findobj(plt.Polygon)[0]
vertices = poly.get_path().vertices
# Keep everything above y == 0. You can define this mask however
# you need, if you want to be more careful in your selection.
keep = vertices[:, 1] > 0
# Construct new polygon from these "good" vertices
new_poly = plt.Polygon(vertices[keep], closed=False, fill=False,
edgecolor=poly.get_edgecolor(),
linewidth=poly.get_linewidth())
poly.set_visible(False)
ax.add_artist(new_poly)
plt.draw()
你应该得到如下图: