如何将python pandas scatter_matrix另存为图形?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16536183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 20:49:23  来源:igfitidea点击:

How does one save python pandas scatter_matrix as a figure?

pythonpandas

提问by gus

I have a dataframe that forms a scatter_matrix, but I can't seem to save the image. How do I save it?

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

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

How do I save my_scatter?

如何保存my_scatter

回答by Radical Edward

Assuming you are using matplotlib:

假设您使用的是 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")

回答by herrfz

Are you using IPython? If you're in IPython notebook, have you tried savefig('/path/to/filename.png')?

你在使用 IPython 吗?如果您在 IPython notebook 中,您尝试过savefig('/path/to/filename.png')吗?