2015-01-23 2 views
2

사용자 정의 범례를 작성했지만 패치의 해치를 표시하지 않습니다. 뭐가 문제 야?Matplotlib이 사용자 정의 범례에 해치를 표시하지 않습니다.

import matplotlib.pyplot as plt 
from matplotlib.patches import Patch 
from pylab import * 
t = arange(0.0, 2.0, 0.01) 
s = sin(2*pi*t) 
fig1 = plt.figure(1,(10,10)) 
plt.plot(t, s) 
plt.xlabel('time (s)') 
plt.ylabel('voltage (mV)') 
plt.title('About as simple as it gets, folks') 
plt.grid(True) 
far_patch = Patch(color=[168/256,175/256,175/256], label='Farshore') 
near_patch = Patch(color=[168/256,175/256,175/256], label='Nearshore',  hatch ='o') 
legend=plt.legend(handles=[far_patch, near_patch],loc='upper left',  handlelength=1, handleheight=1,labelspacing=0, fontsize=8,borderaxespad=0.3,handletextpad=0.2) 

frame = legend.get_frame() 
frame.set_edgecolor('none') 

figureName='test' 

plt.savefig(figureName+'.pdf',bbox_inches='tight',dpi=fig1.dpi) 
plt.show() 

감사

+0

최소 작동 예제를 제공하십시오. http://stackoverflow.com/help/how-to-ask – hitzg

답변

3

facecolor과 edgecolor 모두 우선합니다 Patch 객체 색상 키워드. 그래서 그 propably 해치를 올바르게 보여주는 패치와 같은 색상으로. facecolor을 구체적으로 설정하면 문제가 해결되고 edgecolor을 사용하여 해치를 색칠 할 수 있습니다.

그래서 시도 : 만 해치를보고 싶다면

near_patch = Patch(facecolor=[168/256,175/256,175/256], 
        label='Nearshore', hatch ='o') 

enter image description here

당신은 linewidth 제로에 설정할 수 있습니다.