This question already has an answer here:
- How to save a Seaborn plot into a file 9 answers
I have a Pandas dataframe and try to save a plot in a png file. However, it seems that something doesn't work as it should. This is my code:
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")
And I have this error:
AttributeError: 'AxesSubplot' object has no attribute 'savefig'
You could save any seaborn figure like this.
Suppose If you want to create a violin plot to show the salary distribution gender wise. You could do it like this and will save it using the get_figure method.
Use
plt.savefig('yourTitle.png')
If you want to pass a variable:
You could use
plt.savefig
because your picture will come up when you'll callplt.show()