gpt4 book ai didi

python - 是否可以在 matplotlib 中添加一个字符串作为图例项

转载 作者:IT老高 更新时间:2023-10-28 22:13:33 25 4
gpt4 key购买 nike

我正在 matplotlib 中制作一些图,并想为一些数据添加解释性文本。我想在我的图例中有一个字符串作为“0-10”项上方的单独图例项。有谁知道是否有可能的方法来做到这一点?

enter image description here

这是我传奇的代码:
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()

enter image description here

关于python - 是否可以在 matplotlib 中添加一个字符串作为图例项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16826711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com