我有以下数据集:
x = [0, 1, 2, 3, 4]
y = [ [0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[9, 8, 7, 6, 5] ]
现在我用:
import matplotlib.pyplot as plt
plt.plot(x, y)
但是,我想用这个命令标记3 y 数据集,当调用 .legend()
时会出现一个错误:
lineObjects = plt.plot(x, y, label=['foo', 'bar', 'baz'])
plt.legend()
File "./plot_nmos.py", line 33, in <module>
plt.legend()
...
AttributeError: 'list' object has no attribute 'startswith'
当我检查 lineObjects
:
>>> lineObjects[0].get_label()
['foo', 'bar', 'baz']
>>> lineObjects[1].get_label()
['foo', 'bar', 'baz']
>>> lineObjects[2].get_label()
['foo', 'bar', 'baz']
仅仅使用 .plot()
方法就可以优雅地分配多个标签吗?