2013-12-10 1 views
3

동일한 플롯에서 다른 데이터 세트와 레이블이있는 범례로 3D 산점도를 만들고 싶습니다. 내가 직면하고있는 문제는 전설을 올바르게 추가 할 수 없다는 것과 빈 레이블이있는 그림을 http://tinypic.com/view.php?pic=4jnm83&s=5#.Uqd-05GP-gQ의 그림으로 얻는 것입니다. 더 구체적으로 말하자면, 오류가 발생합니다 : "warnings.warn ("범례는 % s을 (를) 지원하지 않습니다.) \ n 프록시 아티스트를 대신 사용하십시오. \ n \ nhttp : //matplotlib.sourceforge.net/users/legend_guide.html#using-proxy- 아티스트 \ n "% (str (orig_handle))) /usr/lib/pymodules/python2.7/matplotlib/legend.py:610 : UserWarning : 범례는 을 지원하지 않습니다. 대신 프록시 아티스트를 사용하십시오." 나는 다른 대략 비슷한 예를 본Matplotlib에서 scatter()를 사용하여 3D 산점도에 범례 추가

import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D 
import random 
import csv 
from os import listdir 
from os.path import isfile, join 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 

handles = [] 
colors = ['blue', 'red'] 

X1 = range(0,10) 
Y1 = range(0,10) 
Z1 = range(0,10) 

random.shuffle(X1) 
random.shuffle(Y1) 
random.shuffle(Z1) 

scatter1 = ax.scatter(X1, Y1, Z1, c = colors[0], marker = 'o') 

random.shuffle(X1) 
random.shuffle(Y1) 
random.shuffle(Z1) 

scatter2 = ax.scatter(X1, Y1, Z1, c = colors[1], marker = 'v') 

ax.set_xlabel('X', fontsize = 10) 
ax.set_ylabel('Y', fontsize = 10) 
ax.set_zlabel('Z', fontsize = 10) 

ax.legend([scatter1, scatter2], ['label1', 'label2']) 

plt.show() 

하지만 그들 중 누구도는 분산() 플롯을 사용하지 :

내가 지금까지 시도 내용의 예 데모를 검색 할 수 있습니다. 실제 해결책 외에, 누군가 내가 뭘 잘못하고 있는지 설명 할 수 있습니까?

+0

당신이 프록시 예술가에 대한 오류 MSG에 지정된 링크를 살펴나요 전설에 그려진 어떤 라인이없는 = "없음"그래서
이는 linestyle를 하나의 점을 얻으려면? – M4rtini

+0

예.하지만 파이썬을 처음 접했을 때 오류의 원인이 분명하지 않았습니다. – Dio

답변

13
scatter1_proxy = matplotlib.lines.Line2D([0],[0], linestyle="none", c=colors[0], marker = 'o') 
scatter2_proxy = matplotlib.lines.Line2D([0],[0], linestyle="none", c=colors[1], marker = 'v') 
ax.legend([scatter1_proxy, scatter2_proxy], ['label1', 'label2'], numpoints = 1) 

문제는 범례 기능이 3D 분산에 의해 반환 된 유형을 지원하지 않는다는 것입니다. 그래서 당신은 같은 특성을 가진 "더미 플롯"을 만들어서 그것들을 범례에 넣어야합니다.

NumPoints와 = 1 범례에

관련 문제