我有一个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()
你可以保存这样的任何海鸥形象.
假设您想创建一个小提琴图,以显示性别明智的薪资分布.你可以这样做,并使用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')
你可以使用,plt.savefig
因为当你打电话时你的照片会出现plt.show()