I tried the following code (test_seaborn.py
):
import matplotlib
matplotlib.use(\'Agg\')
import matplotlib.pyplot as plt
matplotlib.style.use(\'g
You should just be able to use the savefig
method of sns_plot
directly.
sns_plot.savefig("output.png")
For clarity with your code if you did want to access the matplotlib figure that sns_plot
resides in then you can get it directly with
fig = sns_plot.fig
In this case there is no get_figure
method as your code assumes.
This works for me
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
sns.factorplot(x='holiday',data=data,kind='count',size=5,aspect=1)
plt.savefig('holiday-vs-count.png')
Just FYI, the below command worked in seaborn 0.8.1 so I guess the initial answer is still valid.
sns_plot = sns.pairplot(data, hue='species', size=3)
sns_plot.savefig("output.png")
You would get an error for using sns.figure.savefig("output.png")
in seaborn 0.8.1.
Instead use:
import seaborn as sns
df = sns.load_dataset('iris')
sns_plot = sns.pairplot(df, hue='species', size=2.5)
sns_plot.savefig("output.png")
I use distplot
and get_figure
to save picture successfully.
sns_hist = sns.distplot(df_train['SalePrice'])
fig = sns_hist.get_figure()
fig.savefig('hist.png')
Remove the get_figure
and just use sns_plot.savefig('output.png')
df = sns.load_dataset('iris')
sns_plot = sns.pairplot(df, hue='species', size=2.5)
sns_plot.savefig("output.png")