【发布时间】:2015-11-21 13:30:48
【问题描述】:
我尝试了以下代码(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 会存在并且看起来像这样:
我该如何解决这个问题?
【问题讨论】:
-
@Terry Wang's answer down below 为我工作 -
Python 2.7.12和seaborn 0.7.1 -
seaborn 0.9的单行:sns.regplot(x='age', y='income', data=pd.read_csv('income_data.csv')).get_figure().savefig('income_f_age.png')
标签: python pandas matplotlib seaborn