Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one save python pandas scatter_matrix as a figure?

Tags:

python

pandas

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

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

How do I save my_scatter?

like image 242
gus Avatar asked May 14 '13 06:05

gus


1 Answers

Assuming you are using 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")
like image 174
Radical Edward Avatar answered Nov 14 '22 22:11

Radical Edward