test_seaborn.py
):import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
import seaborn as sns
sns.set()
df = sns.load_dataset('iris')
sns_plot = sns.pairplot(df, hue='species', size=2.5)
fig = sns_plot.get_figure()
fig.savefig("output.png")
#sns.plt.show()
但是我遇到了这个错误:
Traceback (most recent call last):
File "test_searborn.py", line 11, in <module>
fig = sns_plot.get_figure()
AttributeError: 'PairGrid' object has no attribute 'get_figure'
我期望最终的
output.png
存在,并且呈现如下所示:
如何解决这个问题?
Python 2.7.12
和seaborn 0.7.1
中都可以使用。 - Cristian E. Nunoseaborn 0.9
的一行代码:sns.regplot(x='age', y='income', data=pd.read_csv('income_data.csv')).get_figure().savefig('income_f_age.png')
- Anton Tarasenko