2009-05-16 5 views
5

시각화하려는 다른 클래스의 데이터 포인트가 있습니다. 다음은 내가 얻은 이미지입니다. http://imgur.com/1x97hMatplotlib : 범례가 제대로 표시되지 않음

3000 개의 데이터 클래스가 있으며 각각 300 개씩 있습니다. 그것들은 하나의 배열 d에 연결되어 있습니다. 레이블은 labels에 있습니다.

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() 

나의 전설이 왜 망쳐 졌는지 실마리가 있습니까?

+0

전설에 열거 된 항목이 10 개만 있어야한다는 것을 정확히 알고 있습니까? –

+0

네, 맞습니다. – bayer

답변

3

사람이 직접 실행할 수 있도록 구성된 데이터가 포함 된 자체 포함 예가 도움이됩니다. 다음은 귀하가 게시 한 내용에서 수정 된 자체 포함 된 예입니다. ipython -pylab에 Matplotlib의 최신 svn 개정판이 나와 있습니다. 전설 관련 버그가 최근에 수정 된 것 같습니다.

자동 전설 기능과 관련된 버그를 가정

example figure http://www.iki.fi/jks/tmp/legend.png

, 당신은 당신이 원하는 일에 대해 명시 적으로 존재하여 해결할 수 있습니다

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 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() 
관련 문제