2014-07-18 4 views
0

질문에서, 나는 윤곽 플롯을 가지고 있으며 if에 대한 전설을 보여주고 싶습니다.윤곽선 플롯 범례 - Matplotlib

부정적인 수준

긍정적

에 대한

고체 라인

I에 대한 점선 :

내가 사용하는 등고선 플롯 스타일을 사용하고 있습니다 그들에 대한 전설을 갖고 싶다. == 부정 및 단단함 == 긍정).

herehere이라는 접근 방법을 시도했습니다. 그러나 아래에서 볼 수 있듯이 올바른 결과가 표시되지 않습니다.

enter image description here

# Draw the scalar field level curves 
div_field = plt.contour(x, y, div_scalar_field, colors='white') 
rot_field = plt.contour(x, y, rot_scalar_field, colors='lightgoldenrodyellow') 
labels = ['Div Neg', 'Div Pos', 'Rot Neg', 'Rot Pos'] 
div_field.collections[0].set_label(labels[0]) 
div_field.collections[-1].set_label(labels[1]) 
rot_field.collections[0].set_label(labels[2]) 
rot_field.collections[-1].set_label(labels[3]) 

는 난 그냥 긍정적 인 수준을 가지고있는 사업부 스칼라 필드에, 나는 같은 선 스타일로 두 개의 레이블을 가지고있다.

나는 내가 원하는 것을 어떻게 얻을 수 있는지 궁금합니다.

미리 감사드립니다.

나는 (그것이 가장 좋은 방법이 있는지 모르겠다)이 수동으로 설정 전설 해결할 수

답변

0

:

div_neg = plt.Line2D((0, 1), (0, 0), color='white', linestyle='--', linewidth=2) 
div_pos = plt.Line2D((0, 1), (0, 0), color='white', linestyle='-', linewidth=2) 
rot_neg = plt.Line2D((0, 1), (0, 0), color='lightgoldenrodyellow', linestyle='--', linewidth=2) 
rot_pos = plt.Line2D((0, 1), (0, 0), color='lightgoldenrodyellow', linestyle='-', linewidth=2) 

plt.legend([rot_max, div_neg, div_pos, rot_neg, rot_pos], 
      ['Rot Max Points', 'Div Neg', 'Div Pos', 'Rot Neg', 'Rot Pos']) 

enter image description here