我有一个 Pandas 数据框并尝试将绘图保存在 png 文件中。然而,似乎有些事情并没有按预期进行。这是我的代码:
import pandas
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style='ticks')
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'
你可以像这样拯救任何 Seaborn 人物。
假设您想创建一个小提琴图来显示工资分配的性别。您可以这样做,并使用 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')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)