0

I have some code that is plotting the importance of variables from a random forest.

I can't seem to shift the plot over so that the x axis begins at zero.

The gap here along the x axis between -0.01 and 0.00 is very large and I'd like to get rid of it:

enter image description here

I included this line in my code:

plt.xlim([-0.5, 0.07]) and it didn't help:

enter image description here

Thanks for looking at this.

from pylab import rcParams
rcParams['figure.figsize'] = 5, 10

importances = rf.feature_importances_
std = np.std([tree.feature_importances_ for tree in rf.estimators_],
             axis=0)
indices = np.argsort(importances)

list_of_labs = range(0,35)

plt.title("Feature importances")

plt.barh(range(X.shape[1]), importances[indices],
       color="r", xerr=std[indices], align="center")

plt.yticks(range(X.shape[1]), list_of_labs)

plt.ylim([-0.5, X.shape[1]])

plt.show()
Monica Heddneck
  • 2,973
  • 10
  • 55
  • 89
  • Errr... You know about `xlim` but don't seem to be able to choose the limits... I mean, have you tried `plt.xlim([0, 0.07])`? – ForceBru Sep 09 '17 at 17:38

1 Answers1

4

You can just set the starting point

plt.xlim(xmin=0)
Antimony
  • 2,230
  • 3
  • 28
  • 38