最佳答案
首先,您可能决定根本不创建图例,而是在图的一角放置一些标签。
import matplotlib.pyplot as plt
import numpy as np
x = np.random.normal(size=160)
plt.hist(x)
plt.text(0.95,0.95, 'something', ha="right", va="top", transform=plt.gca().transAxes)
plt.show()
如果您已经创建了图例并想删除它,您可以通过
plt.gca().get_legend().remove()
然后添加文本。
如果这不是一个选项,您可以像这样将图例句柄设置为不可见:
import matplotlib.pyplot as plt
import numpy as np
x = np.random.normal(size=160)
plt.hist(x, label = 'something')
plt.legend()
leg = plt.gca().get_legend()
leg.legendHandles[0].set_visible(False)
plt.show()
关于matplotlib - 删除 matplotlib 中的图例键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44603480/