feat(py, plot_importance): + values_format as arg (#8540)

This commit is contained in:
Gianfrancesco Angelini 2022-12-07 17:47:28 +01:00 committed by GitHub
parent 8c6630c310
commit 5540019373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,6 +30,7 @@ def plot_importance(
max_num_features: Optional[int] = None,
grid: bool = True,
show_values: bool = True,
values_format: str = "{v}",
**kwargs: Any
) -> Axes:
"""Plot importance based on fitted trees.
@ -66,6 +67,10 @@ def plot_importance(
The name of feature map file.
show_values : bool, default True
Show values on plot. To disable, pass False.
values_format : str, default "{v}"
Format string for values. "v" will be replaced by the value of the feature importance.
e.g. Pass "{v:.2f}" in order to limit the number of digits after the decimal point
to two, for each value printed on the graph.
kwargs :
Other keywords passed to ax.barh()
@ -109,7 +114,7 @@ def plot_importance(
if show_values is True:
for x, y in zip(values, ylocs):
ax.text(x + 1, y, x, va='center')
ax.text(x + 1, y, values_format.format(v=x), va='center')
ax.set_yticks(ylocs)
ax.set_yticklabels(labels)