2016-06-20 5 views
1

Variable x geht von 0 bis 19. Aber ich habe andere Beispiele, wo es von 0 bis 28 oder von 0 bis 5 gehen wird. Also, wie kann ich das einstellen, um automatisch zu sein anstatt alle Zahlen zu schreiben, wie ich es in "plt.xticks" getan habe?Wie man automatisch die Größe der X-Achse einstellt

for i in range(x.shape[1]): 
     xA=x[:, i].reshape(-1,1) 
     skf = StratifiedKFold(y, n_folds=2, shuffle=True) 
     scoresSKF = cross_validation.cross_val_score(clf, xA, y, cv=skf) 

     plt.ylabel('Accuracy') 
     plt.xlabel('Features')  
     plt.title('Accuracy by feature: Random Forest') 

     plt.xticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19], rotation = 'vertical') 
    plt.show() 

Antwort

1
import numpy 
... 
x_ticks = numpy.arange(i+1) #As the loop starts in 1, the plot will be 0->18. So I add 1 because I want the plot 0->19 
plt.xticks(x_ticks, rotation = 'vertical') 
Verwandte Themen