2017-03-12 1 views
0

필자는 sklearn 분류 보고서를 플로팅하고 있으며 생성 된 플로트가 매우 좁기 때문에 라벨을 읽기가 어렵습니다. 플롯팅 코드를 얻기 위해 게시판 here을 사용했습니다.Matplotlib 플롯 확대

가로로이 플롯을 늘리는 방법에 대한 제안 사항이 있으십니까? 당신이

def plot_classification_report(cr, title='Classification report ', with_avg_total=False, cmap=plt.cm.Blues): 

    lines = cr.split('\n') 

    classes = [] 
    plotMat = [] 
    for line in lines[2 : (len(lines) - 3)]: 
     #print(line) 
     t = line.split() 
     # print(t) 
     classes.append(t[0]) 
     v = [float(x) for x in t[1: len(t) - 1]] 
     #print(v) 
     plotMat.append(v) 

    if with_avg_total: 
     aveTotal = lines[len(lines) - 1].split() 
     classes.append('avg/total') 
     vAveTotal = [float(x) for x in t[1:len(aveTotal) - 1]] 
     plotMat.append(vAveTotal) 


    plt.imshow(plotMat, interpolation='nearest', cmap=cmap) 
    plt.title(title) 
    plt.colorbar() 
    x_tick_marks = np.arange(3) 
    y_tick_marks = np.arange(len(classes)) 
    plt.xticks(x_tick_marks, ['precision', 'recall', 'f1-score'], rotation=45) 
    plt.yticks(y_tick_marks, classes) 
    #plt.tight_layout() 
    plt.ylabel('Classes') 
    plt.xlabel('Measures') 

plot_classification_report(classification_report(y_test, y_pred)) 

plot_output_too_narrow

답변

0

기본적으로 축이 이미지의 가로 세로 비율이됩니다 감사합니다. aspect 인수를 사용하여 imshow으로 변경할 수 있습니다.

"auto"에 넣으면 이미지가 축의 지정된 공간까지 확장됩니다.
또는 높이 너비 비율을 나타내는 숫자로 설정하십시오. number == height/width. 이 경우

plt.imshow(plotMat, interpolation='nearest', cmap=cmap, aspect="auto") 

또는

plt.imshow(plotMat, interpolation='nearest', cmap=cmap, aspect=len(classes)/12.) 

을 시도하고 사용자의 요구에 적응.