Matplotlib:图例未正确显示
我有我想要可视化的不同类的数据点。以下是我得到的图像: 共有10个等级的3000个数据点,每个等级300个。它们被连接在一个数组Matplotlib:图例未正确显示,matplotlib,Matplotlib,我有我想要可视化的不同类的数据点。以下是我得到的图像: 共有10个等级的3000个数据点,每个等级300个。它们被连接在一个数组d中,我对其块进行迭代。标签在标签中给出 pylab.clf() colors = (i + j for j in 'o<.' for i in 'bgrcmyk') for l, c in zip(labels, colors): start, stop = i * 300, (i + 1) * 300 pylab.plot(d[0, start:st
d
中,我对其块进行迭代。标签在标签中给出
pylab.clf()
colors = (i + j for j in 'o<.' for i in 'bgrcmyk')
for l, c in zip(labels, colors):
start, stop = i * 300, (i + 1) * 300
pylab.plot(d[0, start:stop], d[1, start:stop], c, label=l)
pylab.legend(loc='lower left')
pylab.show()
pylab.clf()
颜色=(i+j代表j in'o这将有助于创建一个自包含的示例,可能包含虚构的数据,因此人们可以立即运行它。下面是一个自包含的示例,它根据您在ipython-pylab
中发布的内容进行了修改,对我来说效果很好,最近对Matplotlib进行了svn修订;我认为一些与图例相关的错误最近已经修复
colors = (i + j for j in 'o<.' for i in 'bgrcmyk')
labels = 'one two three four five six seven eight nine ten'.split()
x = linspace(0, 2*pi, 3000)
d = (2+random((2,3000))) * c_[sin(x), cos(x)].T
for i, l, c in zip(range(10), labels, colors):
start, stop = i * 300, (i + 1) * 300
plot(d[0, start:stop], d[1, start:stop], c, label=l)
legend(loc='lower left')
show()
colors=(i+j代表“oAm”中的j我是否正确理解图例中只应列出10项?
colors = (i + j for j in 'o<.' for i in 'bgrcmyk')
labels = 'one two three four five six seven eight nine ten'.split()
x = linspace(0, 2*pi, 3000)
d = (2+random((2,3000))) * c_[sin(x), cos(x)].T
lg = []
for i, l, c in zip(range(10), labels, colors):
start, stop = i * 300, (i + 1) * 300
handle = plot(d[0, start:stop], d[1, start:stop], c, label=l)
lg.append(handle)
legend(lg, labels, loc='lower left')
show()