From 2e9d06443e4793231dd9ac841f7a7879f11b1d47 Mon Sep 17 00:00:00 2001 From: SimonAB Date: Thu, 31 Aug 2017 18:26:54 +0100 Subject: [PATCH] Add show_values option to feature importances plot (#2351) Adding an option to remove the values from the features importances plot in Python. --- python-package/xgboost/plotting.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/python-package/xgboost/plotting.py b/python-package/xgboost/plotting.py index 1ee6d9fd7..7485c0323 100644 --- a/python-package/xgboost/plotting.py +++ b/python-package/xgboost/plotting.py @@ -15,7 +15,7 @@ def plot_importance(booster, ax=None, height=0.2, xlim=None, ylim=None, title='Feature importance', xlabel='F score', ylabel='Features', importance_type='weight', max_num_features=None, - grid=True, **kwargs): + grid=True, show_values=True, **kwargs): """Plot importance based on fitted trees. @@ -45,6 +45,8 @@ def plot_importance(booster, ax=None, height=0.2, X axis title label. To disable, pass None. ylabel : str, default "Features" Y axis title label. To disable, pass None. + show_values : bool, default True + Show values on plot. To disable, pass False. kwargs : Other keywords passed to ax.barh() @@ -83,8 +85,9 @@ def plot_importance(booster, ax=None, height=0.2, ylocs = np.arange(len(values)) ax.barh(ylocs, values, align='center', height=height, **kwargs) - for x, y in zip(values, ylocs): - ax.text(x + 1, y, x, va='center') + if show_values is True: + for x, y in zip(values, ylocs): + ax.text(x + 1, y, x, va='center') ax.set_yticks(ylocs) ax.set_yticklabels(labels)