我正在 matplotlib 中制作一些图,并想为一些数据添加解释性文本。我想在我的图例中有一个字符串作为“0-10”项上方的单独图例项。有谁知道是否有可能的方法来做到这一点?
这是我传奇的代码:
ax.legend(['0-10','10-100','100-500','500+'],loc='best')
最佳答案
替代解决方案,有点脏但很快。
import pylab as plt
X = range(50)
Y = range(50)
plt.plot(X, Y, label="Very straight line")
# Create empty plot with blank marker containing the extra label
plt.plot([], [], ' ', label="Extra label on the legend")
plt.legend()
plt.show()
关于python - 是否可以在 matplotlib 中添加一个字符串作为图例项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16826711/