2

I have the below bar chart generated by using plot_importance.

enter image description here

I increase the fontsize of title, xlabel, ylabel, xticks and yticks by using below code snippet:

plot_importance(clf)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
plt.title("Feature importance", fontsize=16)
plt.xlabel("F score", fontsize=16)
plt.ylabel("Features", fontsize=16)

But I also need to increase the blue bar width and corresponding score fontsize inside the plot.

How do i do that?

Nasir Islam Sujan
  • 362
  • 1
  • 3
  • 20
  • Possible duplicate of https://stackoverflow.com/questions/6986986/bin-size-in-matplotlib-histogram – EMKAY Sep 29 '18 at 06:17
  • Just use a paramater `width=0.5` or some other value you like in `plot_importance(clf), width=0.5` – Sheldore Sep 29 '18 at 10:43
  • 1
    @Bazingaa , there is no `width` parameter in [plot_importance()](https://xgboost.readthedocs.io/en/latest/python/python_api.html#xgboost.plot_importance). BUT there is height parameter which solve my problem. :) – Nasir Islam Sujan Sep 29 '18 at 11:19
  • 1
    @NasirIslamSujan: If you read the parameters, it says "kwargs – Other keywords passed to ax.barh()". And `width` is one of the kwargs of `ax.barh()` – Sheldore Sep 29 '18 at 11:30
  • 1
    The signature of `barh(y, width, height=0.8)` means you can change the `height` to get a wider horizontal bar (that's somehow confusing, as the width of a horizontal bar is the height of a vertical bar). – ImportanceOfBeingErnest Sep 29 '18 at 12:27
  • That's really confusing. The height and width should be defined w.r.t the corresponding axis and not just x-axis – Sheldore Sep 29 '18 at 13:03
  • @Bazingaa I think there were discussions about that already, but I guess it makes sense not to change it now, to keep API breaking changes at minimum. – ImportanceOfBeingErnest Sep 29 '18 at 13:22
  • I think the `height` parameter is what you are looking for, set it to a value between 0 and 1. – lleiou May 28 '19 at 21:10

0 Answers0