【发布时间】:2017-11-08 12:38:58
【问题描述】:
嗨,我有一个 numpy 数组
a = np.random.uniform(0,1, size = (10,3))
我想用自己的标签绘制每一列
plt.plot(a, label = ['label1', 'label2', 'label3'])
plt.legend()
我该怎么做?以上是我的试探性,但没有奏效。
【问题讨论】:
标签: python python-3.x matplotlib legend
嗨,我有一个 numpy 数组
a = np.random.uniform(0,1, size = (10,3))
我想用自己的标签绘制每一列
plt.plot(a, label = ['label1', 'label2', 'label3'])
plt.legend()
我该怎么做?以上是我的试探性,但没有奏效。
【问题讨论】:
标签: python python-3.x matplotlib legend
稍微短一点的方法(因为图例中已经存在句柄):
import numpy as np
import matplotlib.pyplot as plt
a = np.random.uniform(0,1, size = (10,3))
plt.plot(a)
plt.legend(['label1', 'label2', 'label3'])
plt.show()
【讨论】:
我想我找到了here
l1,l2, l3 = plt.plot(a)
plt.legend((l1,l2, l3), ('label1', 'label2', 'label3'))
【讨论】: