我有一个形成 scatter_matrix 的数据框,但我似乎无法保存图像。我该如何保存?
import pandas as pd
my_scatter = pd.scatter_matrix(my_dataframe, diagonal="kde")
我该如何保存my_scatter
?
假设您使用的是 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")
你在使用 IPython 吗?如果您在 IPython 笔记本中,您尝试过savefig('/path/to/filename.png')
吗?