Delaunay simplices的triplot返回两个line2D对象、边和节点的列表:
tri=scipy.spatial.Delaunay(points)
plt.triplot(points[:,0],points[:,1],tri.simplices.copy(),'k-o', label='Delaunay\ntriangulation')如何绘制没有标记的三角形节点的Delaunay三角剖分(只有边)?或者,我想从图例中删除标记条目(将'k-0‘替换为'k-’仍然会在图例中生成两个条目)。

发布于 2017-03-15 01:04:58
plt.triplot会生成两个图例条目。第一个是边,第二个包含点(节点)。即使标记设置为marker=None,也会显示此图例条目。
删除图例条目的最简单方法是获取图例句柄(ax.get_legend_handles_labels()),并仅使用其中的第一个创建图例。
h, l = plt.gca().get_legend_handles_labels()
plt.legend(handles=[h[0]],labels=[l[0]])此时,用户可以选择是否将节点标记为("k-o")或不标记("k-");将只有一个图例条目。

import numpy as np; np.random.seed(6)
import scipy.spatial
import matplotlib.pyplot as plt
points=np.random.rand(7, 2)
tri=scipy.spatial.Delaunay(points)
plt.triplot(points[:,0],points[:,1],tri.simplices.copy(),'k-o',
label='Delaunay\ntriangulation')
h, l = plt.gca().get_legend_handles_labels()
plt.legend(handles=[h[0]],labels=[l[0]])
plt.show()https://stackoverflow.com/questions/42790860
复制相似问题