当前位置:  开发笔记 > 编程语言 > 正文

如何用Python保存Seaborn的情节

如何解决《如何用Python保存Seaborn的情节》经验,为你挑选了2个好方法。

我有一个Pandas数据帧,并尝试在png文件中保存一个图.但是,似乎某些东西不能正常工作.这是我的代码:

import pandas
import matplotlib.pyplot as plt
import seaborn as sns

sns.set()

df = pandas.read_csv("this_is_my_csv_file.csv")
plot = sns.distplot(df[['my_column_to_plot']])
plot.savefig("myfig.png")

我有这个错误:

AttributeError: 'AxesSubplot' object has no attribute 'savefig'

Aman Tandon.. 16

你可以保存这样的任何海鸥形象.

假设您想创建一个小提琴图,以显示性别明智的薪资分布.你可以这样做,并使用get_figure方法保存它.

ax = sns.violinplot(x="Gender", y="Salary", hue="Degree", data=job_data)
#Returns the :class:~matplotlib.figure.Figure instance the artist belongs to
fig = ax.get_figure()
fig.savefig('gender_salary.png')


Anton Protop.. 7

你可以使用,plt.savefig因为当你打电话时你的照片会出现plt.show()



1> Aman Tandon..:

你可以保存这样的任何海鸥形象.

假设您想创建一个小提琴图,以显示性别明智的薪资分布.你可以这样做,并使用get_figure方法保存它.

ax = sns.violinplot(x="Gender", y="Salary", hue="Degree", data=job_data)
#Returns the :class:~matplotlib.figure.Figure instance the artist belongs to
fig = ax.get_figure()
fig.savefig('gender_salary.png')



2> Anton Protop..:

你可以使用,plt.savefig因为当你打电话时你的照片会出现plt.show()

推荐阅读
ERIK又
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有