How can I change the figure size of xgboost's plot importance function?
Trying to pass a figsize=(10,20) fails with the exception of unknown attribute.
You can pass an axis in the ax
argument in plot_importance()
. For instance, use this wrapper:
def my_plot_importance(booster, figsize, **kwargs):
from matplotlib import pyplot as plt
from xgboost import plot_importance
fig, ax = plt.subplots(1,1,figsize=figsize)
return plot_importance(booster=booster, ax=ax, **kwargs)
Then use my_plot_importance()
instead of plot_importance()
You can also set the figure size with:
from xgboost import plot_importance
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (14, 7)
plot_importance(booster=booster)
Only add plt.rcParams["figure.figsize"] = (20,50)
to your code
For example:
from xgboost import plot_importance
plt.figure(figsize=(40,20))
plot_importance(model,max_num_features=100)
plt.rcParams["figure.figsize"] = (20,100)
plt.show()
Adjust (20,100) to enlarge or reduce image size
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With