2016-06-20 3 views
1

Переменная x идет от 0 до 19. Но у меня есть другие примеры, где она будет идти от 0 до 28 или от 0 до 5. Итак, как я могу установить автоматическое вместо того, чтобы писать все числа, как я сделал в «plt.xticks»?как автоматически установить размер оси x

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() 

ответ

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') 
Смежные вопросы