首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将海上绘图保存为svg或png

如何将海上绘图保存为svg或png
EN

Stack Overflow用户
提问于 2021-01-26 06:30:46
回答 1查看 3.8K关注 0票数 2

嗨,我一直试图用plt.savefig("coeff.png")保存我的输出图表,如,svg或png,但我得到的只是一张空白图片。

不管怎样,我可以把我的地块作为图片格式输出吗?

下面是我的密码。

代码语言:javascript
复制
# These are the (standardized) coefficients found
# when it refit using that best alpha
list(zip(X.columns, LGBMR.feature_importances_))

#Now let's make it more presentable in Pandas DataFrame and also in standard form for numbers
df_LGBM_model_coefficients = pd.DataFrame(list(zip(X_train.columns, LGBMR.feature_importances_)))
df_LGBM_model_coefficients.rename(columns={0:'Features', 1: 'Coefficients'}, inplace=True)

df_LGBM_model_coefficients = df_LGBM_model_coefficients.iloc[1:]
df_LGBM_model_coefficients = df_LGBM_model_coefficients.sort_values(by = 'Coefficients', ascending = False)

#only retain the important ones.
df_LGBM_model_coefficients_top_10 = df_LGBM_model_coefficients.head(10)



plt.figure(figsize=(12,12))
sns.set_style('whitegrid')
sns.set(font_scale=0.8)

ax = sns.barplot(x = 'Coefficients',y='Features', data = df_LGBM_model_coefficients_top_10)
ax.set_title("LGBMR Top 10 Features and their coefficients")

for p in ax.patches:
    ax.annotate("%.1f" % p.get_width(), (p.get_x() + p.get_width(), p.get_y() + 0.8), xytext=(5, 10), textcoords='offset pixels')
plt.show()
plt.savefig("coeff.png")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-26 06:38:16

交换代码的最后两行。将plt.savefig("coeff.png")行放在plt.show()行之前。

代码语言:javascript
复制
plt.savefig("coeff.png")
plt.show()
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65896805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档