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

gus*_*gus 5 python pandas

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

import pandas as pd
my_scatter = pd.scatter_matrix(my_dataframe, diagonal="kde")
Run Code Online (Sandbox Code Playgroud)

我该怎么保存my_scatter

Rad*_*ard 6

假设您正在使用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")
Run Code Online (Sandbox Code Playgroud)