如果列名包含汉字,需要设置字体
import lightgbm as lgb
import xgboost as xgb
from matplotlib import pyplot as plt
####lgb,xgb训练完成后............
#设置字体
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
# 使显示图标自适应
plt.rcParams['figure.autolayout'] = True
plt.figure(figsize=(16,10))
#lgb权值图
lgb.plot_importance(model_lgb, max_num_features=30)
plt.title("Featurertances")
plt.show()
#xgb权值图
from xgboost import plot_importance
plot_importance(model_xgb)
本文介绍如何在使用Matplotlib绘制图表时,正确显示中文标签和标题,避免乱码问题。通过设置字体参数,实现lgb和xgb模型特征重要性图表的中文显示。
590

被折叠的 条评论
为什么被折叠?



