From a073a2c3d4a90c7d8caa5982dc11284c53c55d60 Mon Sep 17 00:00:00 2001 From: wxchan Date: Thu, 19 Jan 2017 03:59:50 +0800 Subject: [PATCH] fix ylim with max_num_features in python plot_importance (#1974) --- python-package/xgboost/plotting.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python-package/xgboost/plotting.py b/python-package/xgboost/plotting.py index 2d726374e..ea87a0a50 100644 --- a/python-package/xgboost/plotting.py +++ b/python-package/xgboost/plotting.py @@ -73,7 +73,6 @@ def plot_importance(booster, ax=None, height=0.2, tuples = [(k, importance[k]) for k in importance] if max_num_features is not None: tuples = sorted(tuples, key=lambda x: x[1])[-max_num_features:] - ylim = (-1, max_num_features) else: tuples = sorted(tuples, key=lambda x: x[1]) labels, values = zip(*tuples) @@ -101,7 +100,7 @@ def plot_importance(booster, ax=None, height=0.2, if not isinstance(ylim, tuple) or len(ylim) != 2: raise ValueError('ylim must be a tuple of 2 elements') else: - ylim = (-1, len(importance)) + ylim = (-1, len(values)) ax.set_ylim(ylim) if title is not None: