如何将python pandas scatter_matrix保存为数字?

时间:2013-05-14 06:04:56

标签: python pandas

我有一个形成scatter_matrix的数据框,但我似乎无法保存图像。我该如何保存?

import pandas as pd
my_scatter = pd.scatter_matrix(my_dataframe, diagonal="kde")

如何保存my_scatter

2 个答案:

答案 0 :(得分:5)

假设您正在使用matplotlib:

import pandas as pd
import numpy as np # Only necessary for this example if you don't use it no poblem
import matplotlib.pyplot as plt

# Random data
my_dataframe = pd.DataFrame(np.random.randn(1000, 4), columns=['a', 'b', 'c', 'd'])

# Your plotting funciton
my_scatter = pd.scatter_matrix(my_dataframe, diagonal="kde")

# Save the figure (this can also be a path). As it stands now it will save in this codes directory.
plt.savefig(r"figure_1.png")

答案 1 :(得分:0)

你在使用IPython吗?如果您使用的是IPython笔记本,您是否尝试过savefig('/path/to/filename.png')