Skip to content

Commit 1bc0e65

Browse files
[python-package] Add tests for plotting xlim and max_num_features parameters
1 parent 80ab6d3 commit 1bc0e65

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/python_package_test/test_plotting.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ def test_plot_importance(params, breast_cancer_split, train_data):
9999
with pytest.raises(TypeError, match="xlim must be a tuple of 2 elements."):
100100
lgb.plot_importance(gbm0, title=None, xlabel=None, ylabel=None, xlim="not a tuple")
101101

102+
# test max_num_features parameter
103+
ax5 = lgb.plot_importance(gbm0, max_num_features=5)
104+
assert isinstance(ax5, matplotlib.axes.Axes)
105+
assert len(ax5.patches) == 5
106+
102107
gbm2 = lgb.LGBMClassifier(n_estimators=10, num_leaves=3, verbose=-1, importance_type="gain")
103108
gbm2.fit(X_train, y_train)
104109

@@ -165,6 +170,11 @@ def test_plot_split_value_histogram(params, breast_cancer_split, train_data):
165170
assert ax2.patches[2].get_facecolor() == (0, 0.5, 0, 1.0) # g
166171
assert ax2.patches[3].get_facecolor() == (0, 0, 1.0, 1.0) # b
167172

173+
# test xlim parameter
174+
ax3 = lgb.plot_split_value_histogram(gbm0, 27, xlim=(0, 100))
175+
assert isinstance(ax3, matplotlib.axes.Axes)
176+
assert ax3.get_xlim() == (0, 100)
177+
168178
with pytest.raises(
169179
ValueError, match="Cannot plot split value histogram, because feature 0 was not used in splitting"
170180
):
@@ -535,3 +545,8 @@ def test_plot_metrics(params, breast_cancer_split, train_data):
535545
legend_items = ax4.get_legend().get_texts()
536546
assert len(legend_items) == 1
537547
assert legend_items[0].get_text() == "valid_0"
548+
549+
# test xlim parameter
550+
ax5 = lgb.plot_metric(evals_result0, metric="binary_logloss", xlim=(0, 15))
551+
assert isinstance(ax5, matplotlib.axes.Axes)
552+
assert ax5.get_xlim() == (0, 15)

0 commit comments

Comments
 (0)